我的代码是这样的:
<!DOCTYPE html>
<html>
<head>
<title>Demo</title>
<meta charset="utf-8"/>
<script type="text/javascript">
window.onload=function(){
var data='<html>\
<head>\
<meta charset="utf-8">\
<title>Demo</title>\
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"><\/script>\
<script type="text/javascript">\
$(function(){\
alert("abc");\
});\
<\/script>\
<\/head>\
<body>\
</body>\
</html>';
window.frames["test"].document.open();
window.frames["test"].document.write(data);
window.frames["test"].document.close();
}
</script>
</head>
<body>
<iframe id="test" frameborder="0" name="test"></iframe>
</body>
</html>
这段代码在Chrome、FireFox下均可以正常运行,但在IE下第一次运行会提示$未定义,但刷新后有时又可以正常弹出"abc",所以猜测是运行到alert("abc")这段代码时IE还没有加载完jquery代码。
向大家请教解决方案,通过修改:
$(function(){\
alert("abc");\
});\
这一部分,让代码在IE789上可以正常运行,谢谢!
精慕HU
皈依舞
喵喵时光机
相关分类