
正文
jquery定时更换背景颜色,jquery设置backgroundcolor
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
jquery 动态更改 div 背景色?
用jquery如何实现点击一栏目实现栏目变色,再点击另一栏目也变色,但原来的变回原色,有个数组a(1,2,3)循环遍历输出a的值。jquery 动态更改 div 背景色代码如下:
head
script type="text/javascript" src="/js/jQuery.js"/script
script type="text/javascript"
$(".test").onclick = function(){
$(this).css({"background": "red"});
};
/script
/head
body
div class="test"
style="background-color: gray; width: 300px; height: 200px;"/div
/body
/html$(".test").onclick = function(){
$(this).css({"background": "red"});
};
改为:
$(".test").click = function(){
$(this).css({"background-color": "red"});
};
扩展资料:
jQuery是一个快速、简洁的JavaScript框架,是继Prototype之后又一个优秀的JavaScript代码库(或JavaScript框架)。jQuery设计的宗旨是“write Less,Do More”,即倡导写更少的代码,做更多的事情。它封装JavaScript常用的功能代码,提供一种简便的JavaScript设计模式,优化HTML文档操作、事件处理、动画设计和Ajax交互。
2. jQuery的核心特性可以总结为:具有独特的链式语法和短小清晰的多功能接口;具有高效灵活的css选择器,并且可对CSS选择器进行扩展;拥有便捷的插件扩展机制和丰富的插件。jQuery兼容各种主流浏览器,如IE 6.0+、FF 1.5+、Safari 2.0+、Opera 9.0+等。
3.jquery所有的事件绑定都没有on这个关键字。另外,jquery的事件绑定需要放到readyfunction中去。具体来说:
head
script type="text/javascript" src="/js/jQuery.js"/script
script type="text/javascript"
$(document).ready(function() {
$(".test").click(function() {
$(this).css({"background-color": "red"});
});
});
/script
/head
body
div class="test"
style="background-color: gray; width: 300px; height: 200px;"/div
/body
/html
参考资料:jQuery_百度百科
相关问答
Q1: jquery 的animate()方法可以改变背景颜色么?
jquery 的animate()方法是不可以改变背景颜色的,如果想改变背景颜色,需要引入jquery.color插件,再用animate()来实现背景色变化,具体代码如下:
script src='jquery.animate-colors.js'/script
$("div:contains('你好')").click(function(){$(this).animate({background:"red"},3000)})
下面是实现背景色改变的结果:
扩展资料
jquery改变背景颜色的动态方法
1、脚本方法:
script src=""/script
select class="rez" option value="Not Confirmed"Not Confirmed/option
2、选定方法:
option value="Confirmed" selected="selected"Confirmed/option/selectselect class="rez"
option value="Not Confirmed" selected="selected"Not Confirmed/option
option value="Confirmed"Confirmed/option/select
Q2: jquery鼠标点击事件,改变背景色
你的意思是不是:鼠标移动高亮显示div,点击div就选中当前div(单选),
完整代码如下:
html
head
meta http-equiv="Content-Type" content="text/html; charset=utf-8" /
titlejquery鼠标点击事件,改变背景色/title
script src="jquery-1.7.1.min.js"/script
script type="text/javascript"
$(function () {
//初始化div,并注册事件
var initDiv = function () {
$(".managementPanel div").css("background", "");
$(".managementPanel div").mouseover(function () {
$(this).css("background", "#588600");
})
.mouseout(function () {
$(this).css("background", "");
})
};
initDiv();
$(".managementPanel div")
.click(function () {
initDiv();
//当前被点击的div改变背景色
$(this).css("background", "#588600");
//取消当前div的mouseout和mouseover事件
$(this).unbind("mouseout");
$(this).unbind("mouseover");
});
})
/script
/head
body
div class="managementPanel"
divdiv1/div
divdiv2/div
divdiv3/div
divdiv4/div
divdiv5/div
/div
/body
/html
效果图:
关于jquery定时更换背景颜色和jquery设置backgroundcolor的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。






