如何将js动态的写入到某个div中


不能用innerHTML向div中写入"<script></script>"。

document.getElementById('news').innerHTML='<div><h1>呵呵</h1></div><script>alert(100);</script>';

这样插入的javascript是得不到执行的

 

解决方案:

   var oDiv=document.getElementById('news');
   var oScript=document.createElement("script");
   oScript.type="text/javascript";
   oScript.src="{$ectouch_themes}/js/test.js";
   oDiv.appendChild(oScript);

 


 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM