2017-09-18 5 views
0

image1事前移入テキストボックスに動的

すべてのシリアル番号を取得して動的にシリアル数に基づいてテキストボックスを追加する方法テキストボックス に各シリアルを設定するコードです。

$("#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>&nbsp;&nbsp;<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()を使用することができます

+0

しかし、あなたはどんな質問 – lukaleli

+0

どのように私はdyamically $( "#のSerialList番号" +キー).val(値)の数に基づいてテキストボックスを追加することができますを尋ねたことがありますか? – shwetha

答えて

0

代わりにString.prototype.repeat()

let n = 5; 
 

 
document.body 
 
.insertAdjacentHTML("beforeend", "<input>".repeat(n));

+0

これはメインページにテキストボックスを追加しますが、IDを使用して特定のページでどのように使用しますか? – shwetha

+0

'document.body'に' document.getElementById( "id") 'を代入します。 – guest271314

+0

私は自分のHTMLとJSコードを追加しました、編集ボタンでテキストボックスを動的に生成していますが、シリアルの数に基づいてテキストボックス、テキストボックスは上記のコードで示した形式である必要があります。また、私はurコードを追加しようとしましたが、カウントに基づいて追加しませんでした – shwetha

関連する問題