그래서이 모든 아침 - 및 나는 꽤 코드를 올바른지 알고 있지만 내가 동적으로 생성 된 입력 테이블을 포함하려고 노력하고 설명하는 tr/td 거기에. html/wrap/append 등의 기능을 검토 한 결과 ... :--(jquery 줄 바꿈 (동적 요소)
전체 스크립트에 대한 주석을 확인하십시오. 그러나 실제로이 내용이 중요합니다. 도움이 될만한 점이 있으시면.
나는 랩 및 문서 쓰기를 시도했지만 무엇 내가 기존 문서를 지우고 새 문서를 시작합니다 $(document).ready()
에 document.write()
사용
$(document).ready(function() {
$('#btnAdd').click(function() {
var num = $('.clonedInput').length; // how many "duplicatable" input fields we currently have
var newNum = new Number(num + 1); // the numeric ID of the new input field being added
//http://charlie.griefer.com/blog/2009/09/17/jquery-dynamically-adding- form-elements/
// create the new element via clone(), and manipulate it's ID using newNum value
var newElem = $('#input' + num).clone().attr('id', 'input' + newNum).wrap('<td />');
// manipulate the name/id values of the input inside the new element
newElem.children(':first').attr('id', 'name' + newNum).attr('name', 'name' + newNum).val('');
newElem.children(':second').attr('id', 'amt' + newNum).attr('name', 'amt' + newNum).val('');
newElem.children(':third').attr('id', 'value' + newNum).attr('name', 'value' + newNum).val('');
newElem.children(':fourth').attr('id', 'test' + newNum).attr('name', 'test' + newNum).val('');
// insert the new element after the last "duplicatable" input field
document.write("<tr>");
$('#input' + num).after(newElem);
document.write("</tr>");
귀하의 질문이 무엇인지 명확히 할 수 있습니까? –
'prepend()''append()'에서 jQuery API를 살펴 보겠습니다.이 방법은'document.write()'보다 훨씬 편하다고 생각합니다. – Smamatti