すべてのシリアル番号を取得して動的にシリアル数に基づいてテキストボックスを追加する方法テキストボックス に各シリアルを設定するコードです。
$("#SerialList #" + key).val(value);
if(key == "SERIALNO_LIST")
{
var array = value.split(",");
for(i = 0; i < array.length; i++){
j = i + 1;
}
$("#SerialList #OLDSERIAL" + j).val(array[i].trim());
}
EDIT機能:
function insertRow() {
var table = document.getElementById('createTable');
var row = table.insertRow(table.rows.length - 1);
for (var colIndex = 0; colIndex < numOfCols; colIndex++) {
var cell = row.insertCell(0);
var input = document.createElement('input');
input.setAttribute('type', 'text');
input.id = "SERIAL" + cellIndex;
input.addEventListener('focus', function(e){
return SerialAutoComplete(this);
});
cell.appendChild(input);
cellIndex++;
}
}
<div id="editSerialList" title="Edit Engine Build">
<B>Group Name:</B> <input type="text" id="GROUPNAME" size="50"/>
<table cellpadding="10" id="EditTable">
<tr><td colspan="4"><div id="STATUSDIVID" style="width:580px;"></div></td></tr>
<tr><td><input type="hidden" id="BATCHNO" name="BATCHNO"></td></tr>
<tr>
<td><input type="text" id="OLDSERIAL1" onfocus="SerialAutoComplete1(this)" /></td>
<td><input type="text" id="OLDSERIAL2" onfocus="SerialAutoComplete1(this)" /></td>
<td><input type="text" id="OLDSERIAL3" onfocus="SerialAutoComplete1(this)" /></td>
<td><input type="text" id="OLDSERIAL4" onfocus="SerialAutoComplete1(this)" /></td>
</tr>
<tr>
<td class="add-users">Add Users:</td>
<td colspan="3" style="border:none; padding:8px;">
<select id="addUsers2" name="addUsers2" multiple="multiple"></select>
<input type="button" value="Add Row" name="AddRow" id="AddRow" class="button-green engineCancel" onClick="insertRow1()" /></td>
</tr>
</table>
</div>
私の値の数が5であれば、私は私が値を設定することができる前に、すなわち事前移入/テキストボックスを追加し、テキストボックスを設定する前に5つのテキストボックスを追加する必要があります。
あなたがdocument
let n = 5;
document.body
.insertAdjacentHTML("beforeend", Array(n).fill("<input>").join(""));
内の特定の要素にHTML文字列を追加するために、パラメータとして""
をパラメータとパラメータとして渡さ"<input>"
とArray.prototype.fill()
として渡された番号、Array.prototype.join()
で.insertAdjacentHTML()
をArray()
を使用することができます
しかし、あなたはどんな質問 – lukaleli
どのように私はdyamically $( "#のSerialList番号" +キー).val(値)の数に基づいてテキストボックスを追加することができますを尋ねたことがありますか? – shwetha