我的代碼是這樣的:
<!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下均可以正常運(yùn)行,但在IE下第一次運(yùn)行會提示$未定義,但刷新后有時又可以正常彈出"abc",所以猜測是運(yùn)行到alert("abc")這段代碼時IE還沒有加載完jquery代碼。
向大家請教解決方案,通過修改:
$(function(){\ alert("abc");\});\
這一部分,讓代碼在IE789上可以正常運(yùn)行,謝謝!
向大家請教一個IE加載JS順序問題?
森林海
2018-12-06 17:36:32