我给iframe写了一些html和js,在IE7/8/9中不起作用,错误消息是:$没有定义?
我的代码是:
<!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["code_result"].document.open();
window.frames["code_result"].document.write(data);
window.frames["code_result"].document.close();
}
</script>
</head>
<body>
<iframe id="code_result" frameborder="0" class="frame_result" name="code_result"></iframe>
</body>
</html>
谁能告诉我为什么?感谢
更新
这个错误只在IE78/9中显示,它在Chrome和FireFox 中运行良好
这不是加载I帧内容的代码。这是订单。只需将Iframe脚本封装在窗口onload函数中,就可以让jquery先加载。测试并在例如中工作
添加:
$(document).ready({
alert('123');
});
在运行代码之前,您需要在I帧中加载jquery。JQuery尚未加载。