简体   繁体   English

JQUERY在本地计算机上不起作用

[英]JQUERY won't work on local machine

I'm trying JQUERY on my machine, but for some reason, nothing seems to work. 我正在计算机上尝试JQUERY,但由于某种原因,似乎没有任何效果。 Here's the test file: 这是测试文件:

<html>
<head>
<script type="text/css" src="jquery.js">
</script>
<script type="text/javascript">
    $("p").mouseover(function () {
      $(this).css("color","black");
    });

    $(document).ready(function(){
$("body").css("background-color","black");
$("body").css("color","white");
});
</script>
</head>
<body>
<h1>This is a test</h1>
<p>Roll over me!</p>
</body>
</html>

Nothing in there works. 那里什么都没有。 Also, if anybody wants to know, accessing through my domain and through the local both don't work. 另外,如果有人想知道,通过我的域和本地访问都无效。 I'm really confused, because I copied most of that code off the internet, just in case there was something wrong with my typing. 我真的很困惑,因为我将大部分代码从互联网上复制了下来,以防万一我的打字有问题。

For some reason, firefox is throwing this error: 由于某些原因,firefox抛出此错误:

Code: Evaluate 代码:评估
$ is not defined $未定义
http://hussain.mooo.com/jq.html http://hussain.mooo.com/jq.html
Line: 6 行数:6
$ is not defined $未定义
http://hussain.mooo.com/jq.html http://hussain.mooo.com/jq.html
Line: 6 行数:6

New code (moved the p onmouseover handeler) 新代码(移动了鼠标悬停处理器)

    <script src="jquery.js" type="text/css">
</script>
<script type="text/javascript">
$(document).ready(function(){
    $("p").mouseover(function () {
      $(this).css("color","black");
    });
$("body").css("background-color","black");
$("body").css("color","white");
});
</script>

Specify correct type for javascript file: 为javascript文件指定正确的类型:

<script type="text/javascript" src="jquery.js"></script>

Update 更新资料

You're currently using type="text/css" as content type for javascript file which is incorrect. 您当前正在使用type="text/css"作为javascript文件的内容类型,这是不正确的。 Try to copy above code into your script. 尝试将以上代码复制到脚本中。

Screenshot 屏幕截图

removed dead ImageShack link 删除了死的ImageShack链接

安装firebug,然后在“控制台”选项卡中查看其内容。

您应该将鼠标悬停处理程序的附件移至$(document).ready(...),因为在文档准备好之前该段不一定存在,因此无法将处理程序附加到该段上。

Download the latest version of jQuery "jquery-1.3.2.min.js" and link the file correctly. 下载最新版本的jQuery“ jquery-1.3.2.min.js”并正确链接文件。 and try this, 尝试一下

<script type="text/javascript">
$(function(){
    $("p").mouseover(function () {
      $(this).css("color","black");
    });

    $("body").css("background-color","black");
    $("body").css("color","white");
});
</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM