【发布时间】:2013-12-16 09:32:32
【问题描述】:
我使用Javascript 动态添加textbox,以便用户在一个进程中添加更多项目。这是添加textboxes的代码:
<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>
当用户单击“添加文本”按钮时,将出现一组(四个textboxes)。我的问题是即使用户单击并将数据输入到那些textbox 中,它也只会插入一组数据(这是最后一组输入)。这是因为textbox 的“名称”是相同的。如何插入这些多个数据?或者如何为添加的textbox 设置唯一名称以便将它们插入数据库?
【问题讨论】:
-
你能提供一个jsfiddle吗?
标签: javascript php sql-insert html