<div class="htmlarea"> <textarea id="runcode14477"> <script> //建一个row行,col列的表格 var tbl, tbody, tr, td, text, i,j,row,col; row=10;col=15; var theDoc = document; var theBody = theDoc.body; tbl = theDoc.createElement("TABLE"); tbl.border = "1"; tbl.setAttribute("id","abc"); tbody = theDoc.createElement("TBODY"); tbl.insertBefore(tbody, null); theBody.insertBefore(tbl, null); for (i=0; i<row; i++) { tr = theDoc.createElement("TR"); for (j=0;j<col;j++) { td = theDoc.createElement("TD"); text = theDoc.createTextNode("Text"); tbody.insertBefore(tr, null); tr.insertBefore(td, null); td.insertBefore(text, null); } } var a="aaa"; var b="bbb"; document.getElementById("abc").attachEvent("onclick",function(){alert(a);alert(b)}); </script> </textarea><br><input onclick="runEx('runcode14477')" type="button" value="运行代码"> <input onclick="doCopy('runcode14477')" type="button" value="复制代码"> <input onclick="doSave(runcode14477)" type="button" value="保存代码">[Ctrl+A 全选 注:<a href="http://www.jb51.net/article/23421.htm" title="查看具体详情" target="_blank">如需引入外部Js需刷新才能执行</a>]</div>