【发布时间】:2015-05-04 12:53:57
【问题描述】:
编辑:
在这里,它显示为评论。在我的 IDE 中,它显示为代码。太奇怪了(代码集 #2):
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="bootstrap-3.3.2-dist/js/bootstrap.min.js"></script>
我有两个文件。一个有 cmets,一个没有。第一组代码功能完美。第二组代码在 JavaScript 控制台中告诉我Uncaught ReferenceError: $ is not defined,并没有调用警报。为什么 cmets 会影响我的脚本?
代码集 #1
<!DOCTYPE html>
<html lang="en">
<head>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="bootstrap-3.3.2-dist/js/bootstrap.min.js"></script>
</head>
<body>
<script>
$(function () {
alert("JQUERY!");
});
</script>
</body>
</html>
代码集 #2
<!DOCTYPE html>
<html lang="en">
<head>
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="bootstrap-3.3.2-dist/js/bootstrap.min.js"></script>
<![endif]-->
</head>
<body>
<script>
$(function () {
alert("JQUERY!");
});
</script>
</body>
</html>
【问题讨论】:
-
如果不包含jQuery,则不能使用jQuery(
$是jQuery创建的)。 -
很奇怪。这在我的 IDE 中没有作为评论出现
-
您注释掉包括 jQuery 脚本并期望 jQuery 能够工作。
-
使用
<!--[if lt IE 9]>,您已经注释掉了除 IE -
我猜你想在 jQuery
<script>之前移动<![endif]-->。
标签: javascript html comments