日期:2014-05-16 浏览次数:20439 次
<div id ="testdiv">div </div> <script> var inputElem = document.createElement("input"); //创建组建 inputElem.name = "name"; inputElem.type = "checkbox"; inputElem.checked = "true"; inputElem.onclick=myfun; //注册监听事件,监听函数为myfun var labelSpan = document.createElement("span"); var br = document.createElement("br"); alert(document.getElementById("testdiv")); document.getElementById('testdiv').appendChild(inputElem); function myfun() { alert("ok"); } </script>