3
검색 한 결과 내 문제를 해결하기위한 답을 찾을 수 없습니다. 나는 jQuery에 대해 꽤 놀랍다. 두 개의 다른 영역에서 입력 필드를 추가/삭제하려고한다. 내가 추가/제거 (항목을 찾을 수)를 원하는 두 번째 부분을 수용하기 위해 jQuery와 HTML 코드를 편집 해 보았지만 제대로 작동하지 않습니다. 어떤 도움이라도 대단히 감사하겠습니다!jQuery - 양식에서 입력 필드 추가/제거
jQuery를 :
<script type="text/javascript">
$(document).ready(function() {
$('#btnAdd2').click(function() {
var num2 = $('.clonedInput2').length; // how many "duplicatable" input fields we currently have
var newNum = new Number(num2 + 1); // the numeric ID of the new input field being added
// create the new element via clone(), and manipulate it's ID using newNum value
var newElem2 = $('#input2' + num2).clone().attr('id', 'input2' + newNum);
// manipulate the name/id values of the input inside the new element
newElem2.children(':first').attr('id', 'name' + newNum).val(null);
// insert the new element after the last "duplicatable" input field
$('#input2' + num2).after(newElem2);
// enable the "remove" button
$('#btnDel2').attr('disabled','');
});
$('#btnDel2').click(function() {
var num = $('.clonedInput2').length; // how many "duplicatable" input fields we currently have
$('#input2' + num).remove(); // remove the last element
// enable the "add" button
$('#btnAdd2').attr('disabled','');
// if only one element remains, disable the "remove" button
if (num-1 == 1)
$('#btnDel2').attr('disabled','disabled');
});
$('#btnDel2').attr('disabled','disabled');
});
</script>
HTML :
이<form id="myForm" action="process_call.php" method="post">
<div id="input1" style="margin-bottom:4px;" class="clonedInput">
Charge: <input type="text" name="name[]" id="name1" />
</div>
<div>
<input type="button" id="btnAdd" value="Add Another Charge" />
<input type="button" id="btnDel" value="Remove Charge" />
</div>
<div id="input2" style="margin-bottom:4px;" class="clonedInput2">
Item Found: <input type="text" name="item[]" id="item1" />
</div>
<div>
<input type="button" id="btnAdd2" value="Add Another Item" />
<input type="button" id="btnDel2" value="Remove Item" />
</div>
<input type="submit">
</form>
당신을 감사합니다! 나는 당신의 코드와 함께 작동하지 않는 제거 버튼을 수정하기 위해 몇 가지 작은 편집을해야했지만 훌륭하게 작동합니다! – MarkA2049