1 回答

TA貢獻1874條經(jīng)驗 獲得超12個贊
如果我理解正確,您只想將另一個輸入附加到 div。在這種情況下,您只需添加另一個具有不同變量名稱的輸入(input1此處)并將其附加到 div。
var counter = 1; //limits amount of transactions
function addElements() {
if (counter < 5) //only allows 4 additional transactions
{
let div = document.createElement('div');
div.id = 'row' + counter;
document.body.appendChild(div);
let input = document.createElement('input');
input.id='search'+counter;
input.type = 'search';
input.placeholder = 'Search by product name'
div.appendChild(input);
let input1 = document.createElement('input');
input.id='checkbox'+counter;
input.type = 'checkbox';
div.appendChild(input1);
let button = document.createElement('button');
button.id ='button'+counter;
button.type = 'QRscan';
button.innerText = 'QR scan'
div.appendChild(button);
}
counter++
if (counter >= 6) {
alert("You have reached the maximum transactions.")
}
}
<button onclick="addElements()">
Click me
</button>
添加回答
舉報