Home  >  Article  >  Web Front-end  >  Create a table and add events_javascript skills

Create a table and add events_javascript skills

WBOY
WBOYOriginal
2016-05-16 19:27:181096browse

[Ctrl A select all Note: If you need to introduce external Js, you need to refresh to execute
]<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>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn