且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从外部src重新载入HTML中的脚本?

更新时间:2023-12-04 22:54:58

这是我的工作代码.我使用jQuery作为脚本.在您的onclick button event:

Here is my working code. I used jQuery as my script. Use this lines inside your onclick button event:

var script = document.createElement('script');
script.setAttribute('type', 'text/javascript');
script.setAttribute('src', 'jquery.min.js');
document.head.appendChild(script);

然后就可以了.

更多信息.当您执行script.type = 'text/javascript'之类的操作时,您正在对象上设置属性,但这与将该属性与实际的节点属性相关联不一定是同一件事.

Some more info. When you do something like script.type = 'text/javascript' you are setting a property on the object but this is not necessarily the same thing as associating that property with an actual node attribute.