【发布时间】:2011-11-29 07:48:27
【问题描述】:
可能重复:
jQuery animate backgroundColor
Changing the background color of a <div> section
我有以下代码试图在按下按钮后更改文本的背景颜色。情况是它没有做它打算做的事情。这是为什么?这里出了什么问题。
HTML 代码
<html>
<head>
<script type="text/javascript" src="jquery-1.6.4.js"></script>
<script type="text/javascript" src="script.js"></script>
<script type="text/javascript" src="js/jquery-1.6.2.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.8.16.custom.min.js"></script>
<style type="text/css">
#name{
background-color: #FFFFF2;
width: 100px;
}
</style>
</head>
<body>
<input type="button" id="bgcolor" value="Change color"/>
<div id="name">
Abder-Rahman
</body>
</div>
</html>
script.js
$("#bgcolor").click(function(){
$("#name").animate(
{backgroundColor: '#8B008B'},
"fast");}
);
编辑
我想注意到我有一个名为:jquery-ui-1.8.16.custom 的文件夹,这是我将这些文件放入的位置。而且,我引用了 jquery-1.6.4,js,如图所示除了引用当前文件夹中 js 文件夹中的 jquery-ui-1.8.16.custom.min.js 之外,我还将它放在同一个文件夹中。
我在这里做错了什么?这不就是引用jQuery和jQueryUI的方式吗?
使用的浏览器: Mozilla Firefox 6.0.2
文件夹结构:
jquery-ui-1.8.16.custom/abc.html
jquery-ui-1.8.16.custom/script.js
jquery-ui-1.8.16.custom/jquery-1.6.4.js
jquery-ui-1.8.16.custom/js/jquery-ui-1.8.16.custom.min.js
谢谢。
【问题讨论】:
-
为什么要包含 jQuery 两次?
-
It works here。也许是因为你的结束标签错了?即
</body></div>而不是</div></body>? -
我刚刚把它放到了一个 jsfiddle 中,它似乎奏效了。 jsfiddle.net/PGHHt 也许尝试摆脱第二个 jquery 包含?或者其中一些文件可能不存在?