扫码关注官方订阅号
节点上使用innerHTML添加内容时,发现如果innerHTML字符串中存在<script>的标签,则标签内的js语句不能运行以及src属性失效(无法导入外部js文件)。请问如何解决这个问题?
innerHTML可以插入link标签,但无法插入script标签的;script标签的插入可以通过js的appendChild完成。
var oScript = document.createElement('script'); oScript.type = 'text/javascript'; oScript.async = true; oScript.src = url; document.body.appendChild(oScript);
body里面嵌套html文档写法不规范
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
扫描下载App
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
innerHTML可以插入link标签,但无法插入script标签的;script标签的插入可以通过js的appendChild完成。
body里面嵌套html文档写法不规范