3

I just have copied a simple script from W3School and cannot get it running: Here it is:

<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="http://Web Testing/js/jquery-1.8.0.min.js">
</script>
<script>
$(document).ready(function(){
  $("p").click(function(){
    $(this).hide();
  });
});
</script>
</head>
<body>
<p>If you click on me, I will disappear.</p>
<p>Click me away!</p>
<p>Click me too!</p>
</body>
</html>

It works on their Tryit Editor with the following line but does not work even with this line on my Mac under BBEdit

4

4 回答 4

6

you ned to include jquery the link you included is not working

try

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>

also useing the google hosted libraries is a good option because many other website using it so in most case it will get in browser cache

于 2012-12-18T14:58:02.730 回答
2
<script src="http://code.jquery.com/jquery-1.8.3.min.js" type="text/javascript">
   <!--left blank-->
</script>



<script type="text/javascript">

  $(document).ready(function(){

       /*Your code*/

     });

</script>
于 2012-12-18T15:03:14.540 回答
1
<script type="text/javascript" src="http://Web Testing/js/jquery-1.8.0.min.js"></script>

The link to the jquery library is invalid, replace that code with this:

<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
于 2012-12-18T14:59:08.830 回答
1

您需要在使用前包含 jquery。或者,如果您在脚本之后包含 jquery,而不是使用 ready 或 load 事件

tp 包括 jquery 你可以选择谷歌托管库或 jquery

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>

或者

<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
于 2012-12-19T05:01:42.840 回答