
//1、获取和设置样式
$("#tow")attr("class");//获取ID为tow的class属性
$("#two")attr("class","divClass");//设置Id为two的class属性。
//2、追加样式
$("#two")addClass("divClass2");//为ID为two的对象追加样式divClass2
//3、移除样式
$("#two")removeClass("divClass");//移除 ID为two的对象的class名为divClass的样式。
$(#two)removeClass("divClass divClass2")移除多个样式。
//4、切换类名
$("#two")toggleClass("anotherClass") ;//重复切换anotherClass样式
//5、判断是否含有某项样式
$("#two")hasClass("another")==$("#two")is("another");
//6、获取css样式中的样式
$("div")css("color");// 设置color属性值 $(element)css(style)
//设置单个样式
$("div")css("color","red");
//7设置多个样式
$("div")css({fontSize:"30px",color:"red"});
$("div")css("height","30px")==$("div")height("30px");
$("div")css("width","30px")==$("div")height("30px");
<script>
$(document)ready(function(){
var $dh1 = $("#main")width();
alert($dh1) //这个出来没有 px
var $dh2 = $("#main")css("width");
alert($dh2) //这个出来会有 px
}
);
</script>
注:main 是div 的id
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<link rel="stylesheet" href="jqhovercss"><!--这里显示外链式样式-->
<!--<style>这里显示是内嵌式样式,两种方式都可以在下面的jq代码中获取到背景定位的值
a{ background-position: 0px 0px;}
a:hover{ background-position: 120px -20px;}
</style>-->
<script src="jquery-180minjs"></script><!--这里引入jq库,你在使用的时候记住修改路径-->
<script>
$(function(){
var bgPosition = $('a');
bgPositionhover(function(){
alert($(this)css('background-position'))
},function(){
alert('ok')
});
})
</script>
</head>
<body>
<a href="#">1111111111111</a>
</body>
</html>
alert($(window)height()); //浏览器时下窗口可视区域高度
alert($(document)height()); //浏览器时下窗口文档的高度
alert($(documentbody)height());//浏览器时下窗口文档body的高度
alert($(documentbody)outerHeight(true));//浏览器时下窗口文档body的总高度 包括border padding margin
alert($(window)width()); //浏览器时下窗口可视区域宽度
alert($(document)width());//浏览器时下窗口文档对于象宽度
alert($(documentbody)width());//浏览器时下窗口文档body的高度
alert($(documentbody)outerWidth(true));
以上就是关于如何用jquery 控制css样式全部的内容,包括:如何用jquery 控制css样式、用jquery获得div 里面style 的属性、jquery获取css中:hover的样式 , 只需要获取等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)