以下适用于Chrome,Firefox,Opera和Safari,但当然不适用于MSIE 8或MSIE 8兼容性视图:
<html>
<head><title>saffds</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<script type="text/javascript"> alert($);
</script>
</head>
<body>afdskakj</body></html>
MSIE声称$未定义,而其他浏览器显示jQuery的$ -function。
我尝试删除所有临时文件并重新启动MSIE,设置互联网选项&gt;安全&gt;本地互联网“非常低”,但没有帮助。
ajax.googleapis.com的Jquery几天前曾经为我工作,但现在我不知道改变了什么来打破这个。
导致失败的原因是什么?
谢谢,
- 编辑:我已经测试了以下内容,除了不依赖于jQuery和其他文件.js的警报而且不依赖于jQuery的Link1之外,它也不起作用。
<html>
<head><title>saffds</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<script type="text/javascript" src="otherfile.js"></script>
<script type="text/javascript">
$(document).ready(function() {
alert('I love jQuery!');
});
</script>
</head>
<body>afdskakj
<a href="" onclick="alert('Hello world')">Link1</a>
<a href="">Link2</a>
<script type="text/javascript">
$(document).ready(function() {
alert('I love jQuery!');
});
$(document).ready(function() {
$("a").click(function() {
alert("Hello world!");
});
});
</script>
</body></html>
otherfile.js的内容很简单:
alert("otherfile");
答案 0 :(得分:2)
通过重置MSIE解决了我的问题,如下所述:
答案 1 :(得分:0)
看起来你的jQuery文件尚未下载。请查看this tutorial中的“hello jquery”一章。
你需要等到一切准备就绪:
$(document).ready(function() {
$("a").click(function() {
alert("Hello world!");
});
});