Evo*_*lor 1 javascript html5 comments
编辑:
在这里,它显示这是一个评论.在我的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>
Run Code Online (Sandbox Code Playgroud)
我有两个文件.一个有评论,一个没有.第一组代码功能完美.第二组代码Uncaught ReferenceError: $ is not defined在JavaScript控制台中告诉我,并且不会调用警报.为什么评论会影响我的脚本?
代码集#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>
Run Code Online (Sandbox Code Playgroud)
代码集#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>
Run Code Online (Sandbox Code Playgroud)
这些不是普通的评论,而是有条件的评论.请参阅:http://www.quirksmode.org/css/condcom.html
上面的注释评论所有javascript包含,因此它们不会被加载,除了Internet Explorer低于版本9.
您收到错误消息,因为未加载jquery(它在HTML注释中).如果使用例如IE8则不会出现错误.
| 归档时间: |
|
| 查看次数: |
337 次 |
| 最近记录: |