我正在尝试使用JavaScript在按钮的onclick的有序列表中添加文本框,并在添加文本框时增加ID名称

巴拉·维格涅什(Bala Vignesh)

我尝试使用document.createElement,可以很好地添加文本框,但是我无法增加ID名称。我在Metro应用中使用它。

巴拉·维格涅什(Bala Vignesh)
<form>
  No. of lines:
  <input type="text" id="number" value="0"/>
  <br/>
  <input type="button" id="button" value="Add Line" />
</form>
<div>
  <ol id="linedata">
  </ol>
</div>
document.getElementById('button').addEventListener("click", incrementValue);
function incrementValue() {
  var value = parseInt(document.getElementById('number').value, 10);
  value = isNaN(value) ? 0 : value;
  value++;
  document.getElementById('number').value = value;
  var list = document.createElement('li');
  var box = document.createElement('input');
  box.type = 'text';
  box.id = 'line' + value;
  box.placeholder='Line ' + value;
  list.appendChild(box);
  document.getElementById("linedata").appendChild(list);
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

Related 相关文章

热门标签

归档