2015-06-19 79 views
0

這裏是我的代碼如何用另一個文本框中的文本使用jQuery來填充動態文本框?

var rowCount = $('#tblApplIdn tr').length; 
var index = rowCount + 1; 
$('#tblApplIdn').append("<tr><td><input type='hidden' name='identitity.Index' value='" + index + "' /><input type='text' name='identitity[" + index + "].TypeOfIdentification' value=" + $('#TypeOfIdentification').val() + "></td><td><input type='text' class='textreq' name='identitity[" + index + "].IdentityNumber' value=" + value + "></td><td><input type='text' class='textreq' name='identitity[" + index + "].IssueDate' value=" + $('#IssueDate').val() + "></td><td><input type='text' class='textreq' name='identitity[" + index + "].ExpiryDate' value=" + $('#ExpiryDate').val() + "></td><td><input type='text' class='textreq' name='identitity[" + index + "].DateReceived' value=" + $('.receivedDte').val() + "></td><td><input type='text' class='textreq' name='identitity[" + index + "].IssuingAuthority' value=" + $('.issAuthority').val() + "></td><td><input type='text' name='identitity[" + index + "].PlaceofIssue' value=" + $('#PlaceofIssue').val() + "></td><td><input type='text' class='textreq' value=" + $('#Countryofissue option:selected').text() + "><input type='hidden' class='textreq' name='identitity[" + index + "].Countryofissue' value=" + $('#Countryofissue').val() + "></td><td><input type='button' name='remove' class='remove' value='Remove' id='" + index + "'/></tr>"); 

上面的代碼不正確填寫動態文本框。假設我說IdentityNumber = AA 1234,那麼動態文本框只需要AA,並且不會在空格之後填充任何內容。我嘗試了一個變量,然後將該值賦值給該變量,然後將該變量作爲值傳遞,但它的行爲方式相同。我有12左右的選項卡,幾乎所有的選項卡需要添加動態文本框,單擊添加按鈕後,用戶可以選擇添加多個記錄。在檢查元素內,我可以找到

<input type="text" class="textreq valid" name="identitity[2].IdentityNumber" value="AA" 1234 aria-invalid="false"> 

如何在動態文本框中包含整個值。我瀏覽並嘗試了所有我能找到的東西,但它不起作用。任何評論和答案真的很感激。

+0

您沒有正確引用代碼。 –

+0

@BhojendraNepal可以ü發表引用代碼,如你在答案部分說的例子,如果這符合我的要求,我會將其標記爲已接受。謝謝 – User

+0

應該是這樣的:) name =「identitity ['」+ index +「'] .TypeOfIdentification」 –

回答

0

好的。這可能不是一個最佳解決方案,但只是爲了達到您可以使用它的要求!即使我不知道爲什麼你不能追加與空間值,以什麼我該怎麼辦是存儲在每個變量的值,然後把它分配給作爲低於去年tr小號td每個input

DEMO

$('.btnApplIdnDtls').click(function() { 
    var rowCount = $('#tblApplIdn tr').length; 
    var index = rowCount + 1; 
    var IndentifyType=$('#TypeOfIdentification option:selected').text();//get values 
    var IdentifyNum=$("#IdentityNumber").val();//get values 
    var IssueDate=$('#IssueDate').val();//get values 
    $('#tblApplIdn').append("<tr><td><input type='hidden' name='identitity.Index' value='" + index + "' /><input type='text' name='identitity[" + index + "].TypeOfIdentification'></td><td><input type='text' class='textreq' name='identitity[" + index + "].IdentityNumber'></td><td><input type='text' class='textreq' name='identitity[" + index + "].IssueDate'></td><td><input type='button' name='remove' class='remove' value='Remove' id='" + index + "'/></tr>");//simply append it 
    var lasttr=$('#tblApplIdn tr:last'); //get the last tr 
    lasttr.find('td:first input[type="text"]').val(IndentifyType); give its input a value 
    lasttr.find('td:nth-child(2) input').val(IdentifyNum); 
    lasttr.find('td:nth-child(3) input').val(IssueDate); 
}); 
相關問題