日期:2014-05-16  浏览次数:20429 次

JS动态加载和取值问题
表格中第一行中有button   ,select,text,三个控件
请问:如何用JS实现动态加载上面的控件,并把控件里面的值取出来

------解决方案--------------------
<script>
function doit(){
var t = document.getElementById( "t1 ");
alert(t.value);
var s = document.getElementById( "s1 ");
alert(s.value);

}

window.onload = function(){
var tbl = document.getElementById( "tbl ");
tbl.rows[0].cells[0].innerHTML = " <input type= 'button ' id= 'b1 ' value= 'click ' onclick= 'doit(); '> ";
tbl.rows[0].cells[1].innerHTML = " <select id = 's1 '> <option value= '0 '> 0000 </option> <option value= '1 '> 1111 </option> </select> ";
tbl.rows[0].cells[2].innerHTML = " <input type= 'text ' id= 't1 ' value= ' '> ";
}
</script>

<table id= "tbl ">
<tr> <td> </td> <td> </td> <td> </td> </tr>
</table>