获取JS动态生成的HTML控件中的值。
JS动态生成了一行四列的表格,表格中生成了2个HTML文本框,2个HTM按钮。JS代码如果下:
function insertRow()
{
newRow=document.all.yltable.insertRow(-1);
var j_1=document.all.yltable.rows.length;
newcell=newRow.insertCell();
newRow.bgColor='#FFFFFF';
newcell.align='center';
newcell.innerHTML=""+j_1+"";
newcell=newRow.insertCell();
newRow.bgColor='#FFFFFF';
newcell.align='center';
newcell.innerHTML="<input type='text' name='ylText"+j_1+"'/>";
newcell=newRow.insertCell();
newRow.bgColor='#FFFFFF';
newcell.align='center';
newcell.innerHTML="<input type='text' name='hei"+j_1+"' />";
newcell=newRow.insertCell();
newRow.bgColor='#FFFFFF;';
newcell.align='center';
newcell.innerHTML='<input name="button3" type="button" value="删除" onclick="return DelRow()"> <input name="btnAdd" type="button" value="添加">';
document.all.yltable.focus();
}
function DelRow()
{
var currRowIndex=event.srcElement.parentNode.parentNode.rowIndex;
document.all.yltable.deleteRow(currRowIndex);
}
现在需要实现的功能:
在生成的HTML文本框中输入信息,点击生成的HTML(添加)按钮。能获取到文本框中的信息