我使用Javascript
动态添加textbox
以便用户在一个进程中添加更多项目。下面是添加textboxes
代码:如何将动态添加的文本框插入到MySQL数据库中
<script type="text/javascript">
var quantity = document.getElementById('quantity');
var item = document.getElementById('item');
var serial = document.getElementById('serial');
var property = document.getElementById('property');
document.getElementById('add').onclick = function() {
var input = document.createElement('input'),
div = document.createElement('div');
input.type = "text";
input.setAttribute("name", "quant");
div.appendChild(input);
quantity.appendChild(div);
var input2 = document.createElement('input'),
div2 = document.createElement('div');
input2.type = "text";
input2.setAttribute("name", "items");
div.appendChild(input2);
item.appendChild(div);
var input3 = document.createElement('input'),
div3 = document.createElement('div');
input3.type = "text";
input3.setAttribute("name", "serno");
div.appendChild(input3);
serial.appendChild(div);
var input4 = document.createElement('input'),
div4 = document.createElement('div');
input4.type = "text";
input4.setAttribute("name", "proper");
div.appendChild(input4);
property.appendChild(div);
};
</script>
当用户点击的 “添加文本” 按钮,一组(4 textboxes
)将出现。我的问题是,即使用户点击并输入数据到这些textbox
,它只会插入一组数据(这是最后一组输入)。它因为textbox
的“名称”是相同的。我怎样才能插入这些多个数据?或者我怎样才能为添加的textbox
设置一个唯一的名称,以便将它们插入到数据库中?
你能提供一个jsfiddle吗? – Manishearth
http://jsfiddle.net/ehx6M/ 这里是 –