Internet Explorer中“script”标记的“onload”处理程序我一直在使用这个函数将onload处理程序附加到脚本标记,它似乎是互联网上推荐的方式。然而,如果页面已经加载(在8中测试),它在Internet Explorer中不起作用。您可以看到它在普通浏览器中有效(加载脚本时会触发警报)。我错过了什么吗?谢谢
2 回答
慕容708150
TA贡献1831条经验 获得超4个赞
你应该打电话jQuery.getScript
,这正是你正在寻找的。
编辑:这是jQuery的相关源代码:
var head = document.getElementsByTagName("head")[0] || document.documentElement;var script = document.createElement("script");if ( s.scriptCharset ) { script.charset = s.scriptCharset;}script.src = s.url;// Handle Script loading var done = false;// Attach handlers for all browsersscript.onload = script.onreadystatechange = function() { if ( !done && (!this.readyState || this.readyState === "loaded" || this.readyState === "complete") ) { done = true; jQuery.handleSuccess( s, xhr, status, data ); jQuery.handleComplete( s, xhr, status, data ); // Handle memory leak in IE script.onload = script.onreadystatechange = null; if ( head && script.parentNode ) { head.removeChild( script ); } }};// Use insertBefore instead of appendChild to circumvent an IE6 bug.// This arises when a base node is used (#2709 and #4378).head.insertBefore( script, head.firstChild );
添加回答
举报
0/150
提交
取消