Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/362.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Javascript或AJAX动态添加输入框_Javascript - Fatal编程技术网

使用Javascript或AJAX动态添加输入框

使用Javascript或AJAX动态添加输入框,javascript,Javascript,我有一列输入框,最后一行有一个按钮,可以在最后一个输入框下面添加更多的输入框。有什么最好的办法吗?你可以这样做: function addTextBox() { var container = document.getElementById('container'); var txt = document.createElement('input'); txt.type = 'text'; txt.name = "my name"; container.appendChil

我有一列输入框,最后一行有一个按钮,可以在最后一个输入框下面添加更多的输入框。有什么最好的办法吗?

你可以这样做:

function addTextBox()
{
  var container = document.getElementById('container');
  var txt = document.createElement('input');
  txt.type = 'text';
  txt.name = "my name";

  container.appendChild(txt);
}

在上面的代码中,
container
应该是包含文本框的列id。

您使用的是jQuery,还是只使用普通JavaScript?