1
一種類型的輸入他們想要的數量,然後單擊GO,它會創建許多輸入字段。我如何做到這一點,每個人都有自己獨特的名字?jquery創建輸入和輸入數組名稱
我想爲創建的每個輸入唯一的名稱,以便即:
- 1輸入:NAME = 「productcode1」
NAME = 「DESC1」 NAME = 「dollars1」 NAME = 「cents1」 第二輸入:名稱= 「productcode2」
名稱= 「DESC2」 名稱= 「dollars2」 名稱= 「cents2」$(document).ready(function(){ $('#addButton').click(function(){ var count = parseInt($('#quantity').val()); var newHTML = []; for(var i=0;i<count;i++){ newHTML.push('Product Code: <input name="productcode[]" type="text"/> Description: <input name="desc[]" type="text"/> $<input width="100px" type="text" name="dollars[]" size="5" maxlength="6"/>.<input width="50px" type="text" name="cents[]" size="1" maxlength="2"/><br/>'); } $('#sandbox').html(newHTML.join('')); }); });
FYI我也使用PHP,如果它是更容易被納入