javascript动态添加文本框并获取各不同文本框的值
可以动态添加文本框,但是属性都是相同的(下面例子中的new),如果在servlet中区分这些,分别获得各个的值?下面是代码:<scriptlanguage="javasc...
可以动态添加文本框,但是属性都是相同的(下面例子中的new),如果在servlet中区分这些,分别获得各个的值?下面是代码:
<script language="javascript">
function additem(id)
{
var row,cell,str;
row = eval("document.all["+'"'+id+'"'+"]").insertRow();
if(row != null )
{
cell = row.insertCell();
str="<input type="+'"'+"text"+'"'+" name="+'"'+"new"+'"'+" value="+'"'+" "+'"'+"><input type="+'"'+"button"+'"'+" value="+'"'+"Delete"+'"'+" onclick='deleteitem(this,"+'"'+"tb"+'"'+");'>";
cell.innerHTML=str;
}
}
function deleteitem(obj,id)
{
var rowNum,curRow;
curRow = obj.parentNode.parentNode;
rowNum = eval("document.all."+id).rows.length - 1;
eval("document.all["+'"'+id+'"'+"]").deleteRow(curRow.rowIndex);
}
</script> 展开
<script language="javascript">
function additem(id)
{
var row,cell,str;
row = eval("document.all["+'"'+id+'"'+"]").insertRow();
if(row != null )
{
cell = row.insertCell();
str="<input type="+'"'+"text"+'"'+" name="+'"'+"new"+'"'+" value="+'"'+" "+'"'+"><input type="+'"'+"button"+'"'+" value="+'"'+"Delete"+'"'+" onclick='deleteitem(this,"+'"'+"tb"+'"'+");'>";
cell.innerHTML=str;
}
}
function deleteitem(obj,id)
{
var rowNum,curRow;
curRow = obj.parentNode.parentNode;
rowNum = eval("document.all."+id).rows.length - 1;
eval("document.all["+'"'+id+'"'+"]").deleteRow(curRow.rowIndex);
}
</script> 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询