jquery怎么判断对象的背景色

如题所述

只要通过jq获取这个属性的样式值  然后你就可以根据获取的值进行判断了

css方法:
1、取得第一个段落的color样式属性的值。
1    $("p").css("color");    
2、将所有段落的字体颜色设为红色并且背景为蓝色。
1    $("p").css({ color: "#ff0011", background: "blue" });    
12345678910111213141516171819202122    <html><head>    <title>JQuery中如何获取样式属性的值</title>    <script type="text/javascript" src="jquery.js"></script>    <style>        .top {            background: url(Tupian.jpg) no-repeat;            width: 75px;            height: 90px;        }    </style>    <script type="text/javascript">        $(function () {            var url = $("div.top").css("background-image");            alert(url);        })    </script></head><body>    <div class="top"></div></body></html>

温馨提示:答案为网友推荐,仅供参考
相似回答