我想使用javascript动态地将id添加到输入中。我该怎么做。我写了一个函数,但它不起作用。
html
<form>
element 0_0 <input type = "text" class = "elements"></input>
element 0_1 <input type = "text" class = "elements"></input>
element 1_0 <input type = "text" class = "elements"></input>
element 1_1 <input type = "text" class = "elements"></input>
<input type = "button" onclick = "giveId('elements')"></input>
</form>
javascript
function giveId(className){
var array = document.getElementsByClassName(className)
for(var i = 0;i < array.length; i++){
array[i].id = "A" + i;
}
}