我的javascript错了吗?

Kar*_*arl -2 html javascript jquery

非常简单的javascript无效.

我希望DIV隐藏在鼠标上.index.html和script.js位于同一文件夹中.我在Chrome中打开此功能.

index.html的:

<!DOCTYPE html>
<html>
<head>
  <title>Test</title>
  <script> type='text/javascript' src='script.js' </script>
</head>
<body>
  <div>
    Hello world
  </div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

的script.js:

$(document).ready(function() {
    $('div').mouseenter(function () {
        $('div').hide();
    });
});
Run Code Online (Sandbox Code Playgroud)

任何想法为什么这不起作用?

DiM*_*ono 7

改变这个:

<script> type='text/javascript' src='script.js' </script>

对此:

<script type='text/javascript' src='script.js'></script>

'type'和'src'是脚本标记的参数,而不是内部标记的参数.

另外,请确保在HTML中包含jquery库,否则您的脚本将无法正常工作,因为它不知道是什么$意思.