<script language="javascript" type="text/javascript">
function appendit()
{
var utable = document.getElementById("utable");for (var i=0; i<1; i++)
{
var currentRow = utable.insertRow();
for (var j=1; j<3; j++)
{
var button = document.createElement("<input id=\"b"+j+"\" name=\"b"+j+"\" type='button' value=\"AppendButton"+j+"\">");
button.onclick = function () { alert(this.id); }
button.onblur = function () { alert(this.id);}
var currentCell = currentRow.insertCell();
currentCell.appendChild(button);
}
}
}
</script>
</HEAD><BODY onload="appendit();">
<TABLE id="utable" name="utable" width="20%" align="center" border="1">
<TR>
<TD>asdasd</TD>
<TD>asdasd</TD>
</TR>
<TR>
<TD>asdfasd</TD>
<TD>asdfad</TD>
</TR>
</TABLE>
</BODY>
</HTML>

解决方案 »

  1.   

    你可以将onclick="getValeu('a1')"  onblur="clear('a1')"中的a1用变量代替,在js中通过添加一行触发的事件 进行赋值a2,然后就取得a2的值了。
      

  2.   

    onclick="getValeu(this.id)"  onblur="clear(this.id)"
      

  3.   

    <html>
    <head>
    <script language="javascript" type="text/javascript">
    function appendTable()
    {
    var table1 = document.getElementById("Table1");
    var currentRow = table1.childNodes[0];
    var newRow  = currentRow.cloneNode(true); //copy a row including its child nodes
    var childs = newRow.getElementsByTagName("input");
    childs[0].onclick=function(){
    alert('getValue(a2)');
    }; childs[0].onblur=function(){
    alert('clear(a2)');
    }; table1.appendChild(newRow);
    }
    </script>
    </HEAD><BODY onload="appendTable();">
    <TABLE id="Table1"  width="20%" align="center" border="1">
    <TR> 
    <TD><input type="text" onclick="alert('getValue(a1)');"  onblur="alert('clear(a1)');"/></TD>
    </TR>
    </TABLE>
    </BODY>
    </HTML>