JS怎么在页面中插入HTML代码
JS如何在页面中插入HTML代码
比如有一大段表格代码,如何用JS在HTML的指定位置插入代码?
用creatElement()然后appendChild好像不行,代码短的话可以,长的话就插不进去了。
------解决方案--------------------
比如有一大段表格代码,如何用JS在HTML的指定位置插入代码?
用creatElement()然后appendChild好像不行,代码短的话可以,长的话就插不进去了。
------解决方案--------------------
- JScript code
<html> <head> <script> function insert(){ var insertText = "<table><tr><td>any thing</td></tr></table>"; document.getElementById("insert").innerHTML = document.getElementById("insert").innerHTML+insertText; } </script> </head> <body> <button onclick="insert()">Insert</button> <div id="insert"></div> </body> </html>