简单的代码不能在jquery中工作

Tar*_*yüz -1 jquery

在此输入图像描述我在Ubuntu中使用了sublime-text2editör和chrome web浏览器.这个非常简单的代码无法正常工作但是当我在脚本标签中只编写alert("test")时它正在工作但是这个简单的代码现在不能正常工作.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Scroll Activated Animation</title>
<script type="text/javascript" src="../../jquery-2.1.4.js"></script>
<script type="text/javascript">
  $(document).ready(function(){
    $("#test").click(function(){
      alert("test");
    });
  });
</script>
<style type="text/css" rel="stylesheet">
    #test{
    width:50px;
    height:50px;
    background-color: #eee;
    margin: 0 auto;
  }
  </style>
</head>
 <body>
  <div id="test">Click here</div>
 </body>
</html>
Run Code Online (Sandbox Code Playgroud)

jquery源代码没有问题.因为我上面说过只有警报才有效

图片路径:

在此输入图像描述

在此输入图像描述

在此输入图像描述

在此输入图像描述

Pra*_*man 7

检查jQuery的路径是否正确.在您的情况下,路径应该是这样的:

+ jquery-2.1.4.js
+ some_folder
| + some_other_folder
| | + index.html     ----- This is your file.
Run Code Online (Sandbox Code Playgroud)

你给出的代码是完全正确的.您有两种选择:

  1. 纠正jQuery的路径.
  2. 使用CDN: http://code.jquery.com/jquery-2.1.4.js

所以第二个选项是添加以下内容而不是你在jQuery中作为jQuery的引用<head>:

<script type="text/javascript" src="http://code.jquery.com/jquery-2.1.4.js"></script>
Run Code Online (Sandbox Code Playgroud)