javascript - There are js imports in the innerHTML content or the statements cannot run properly.
習慣沉默
習慣沉默 2017-06-30 09:58:51
0
2
922
When using innerHTML to add content on the

node, we found that if there is a <script> tag in the innerHTML string, the js statement in the tag cannot be run and the src attribute is invalid (external js files cannot be imported). How to solve this problem?

習慣沉默
習慣沉默

reply all(2)
typecho

innerHTML can insert link tags, but cannot insert script tags; the insertion of script tags can be completed through appendChild of js.

var oScript = document.createElement('script'); 
oScript.type = 'text/javascript'; 
oScript.async = true; 
oScript.src = url; 
document.body.appendChild(oScript); 
代言

The nested HTML document in the body is not written in a standardized way

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template