例如here代码是这样的:
<html lang="en">
<head>
<!-- whatever -->
<script>
$(function() {
$( "#datepicker" ).datepicker();
});
</script>
</head>
<!-- whatever -->
请注意 <script>
应该包含 type
属性(可能设置为 "text/javascript"
),但此处不存在。
这不是我见过的唯一例子。这样的代码让 Visual Studio 编辑器不高兴 - 它强调了 <script>
并说应该有一个 type
属性。这也让我很好奇。
为什么是type
经常省略?如果我添加 type="text/javascript"
会发生什么- jQuery 会崩溃吗?
最佳答案
那可能是因为 HTML5 does not require a type
attribute on <script>
elements (默认为 "text/javascript"
)。
关于javascript - 为什么 jQuery 示例经常省略脚本类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15204097/