使用jQuery的问题[英] Problem working with jQuery

本文是小编为大家收集整理的关于使用jQuery的问题的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

出于某种原因无法正常工作.我想知道问题是什么.我的代码是:

<script language="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>    
<script language="text/javascript">
function hide() {
    $("#Layer1").hide("fast");
}
</script>
<style type="text/css">
<!--
body {
 background-color: #000000;
}
#Layer1 {
 position:absolute;
 width:200px;
 height:115px;
 z-index:1;
 left: 179px;
 top: 3px;
}
#Layer2 {
 position:absolute;
 width:101px;
 height:80px;
 z-index:2;
 left: 570px;
 top: 473px;
}
-->
</style></head>
<body>
<div id="Layer1"></div>
<div id="Layer2" onclick="hide()"></div>
</body>
</html>

谢谢! :)

推荐答案

您似乎正在混淆script标签形式:

<script type="text/javascript">

与:

<script language="javascript">

(请参阅例如在这里 ).为什么不将标签修复以使用type=?不确定这是否是您的所有问题(发现此问题后,我认为即使有其他问题也需要修复;-)但是这使您感到困惑 me ,并且可能会混淆您的浏览器; - ).

其他推荐答案

我怀疑这是问题所在,但是尝试从hide()(这是一个jQuery函数)更改函数名称,以hideDiv()

之类的东西

因为hide() hide() ($.hide()) ($.hide())我怀疑这是问题所在,但我猜值得一试.

本文地址:https://www.itbaoku.cn/post/627325.html

问题描述

jQuery for some reason isn't working.I'd like to know what the problem is.Here is my code :

<script language="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>    
<script language="text/javascript">
function hide() {
    $("#Layer1").hide("fast");
}
</script>
<style type="text/css">
<!--
body {
 background-color: #000000;
}
#Layer1 {
 position:absolute;
 width:200px;
 height:115px;
 z-index:1;
 left: 179px;
 top: 3px;
}
#Layer2 {
 position:absolute;
 width:101px;
 height:80px;
 z-index:2;
 left: 570px;
 top: 473px;
}
-->
</style></head>
<body>
<div id="Layer1"></div>
<div id="Layer2" onclick="hide()"></div>
</body>
</html>

Thanks! :)

推荐答案

You seem to be confusing the form of the script tag that goes:

<script type="text/javascript">

with the one that goes:

<script language="javascript">

(see e.g. here for some explanation). Why not fix your tags to use just type= instead? Not sure whether that's all your problem (after spotting this one I think it needs to be fixed even if there were others;-) but it's confusing me and could be confusing your browser;-).

其他推荐答案

I doubt it's the problem, but trying changing your function name from hide(), which is a jQuery function, to something else like hideDiv()

Since hide() isn't being used with the jQuery tag ($.hide()) I doubt this is the issue, but worth a shot I guess.