为什么$(.calss).css.("background")返回值为空?
来源:百度知道 编辑:UC知道 时间:2024/05/11 01:44:32
问题RT
代码:
//index.html-------------------
<div>
<ul>
<li><a class='abc' href=#>abc</a></li>
</ul>
</div>
//index.html end---------------
//style.css--------------------
.abc {
background:url(../images/abc.jpg) no-repeat;
display:block;
text-indent:-9999px;
overflow:hidden;
width:55px;
height:27px;
}
//sytle.css end--------------------------
//fuction.js ----------------------------
$(document).ready(function(){
$(.abc).click(function(){
var s=$(.abc).css('background');
alert(s);
});
});
//fuction.js end-------------------------
请高手给以指点。
一楼:方法取到的也是空值
二楼:方法取值时提示 unkonw 应该是background-image末定义
三楼:题目打错了,但代码没问题
代码:
//index.html-------------------
<div>
<ul>
<li><a class='abc' href=#>abc</a></li>
</ul>
</div>
//index.html end---------------
//style.css--------------------
.abc {
background:url(../images/abc.jpg) no-repeat;
display:block;
text-indent:-9999px;
overflow:hidden;
width:55px;
height:27px;
}
//sytle.css end--------------------------
//fuction.js ----------------------------
$(document).ready(function(){
$(.abc).click(function(){
var s=$(.abc).css('background');
alert(s);
});
});
//fuction.js end-------------------------
请高手给以指点。
一楼:方法取到的也是空值
二楼:方法取值时提示 unkonw 应该是background-image末定义
三楼:题目打错了,但代码没问题
var s=$(.abc).css('backGround');
貌似我也取不到,你可以分开一个一个的取啊
$(".abc").css("background-image");
为什么$(.calss).css.("background")返回值为空?
calss是不是应该改成class
var s=$(.abc).css('background');
修改为
var s=$(".abc").css('background');