jquery的css()对组合的属性无法获取(background,font,margin,padding)(ie6、7)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>jquery的background获取问题</title>
<style type="text/css">
	.demo {
		font:12px/24px Verdana, Geneva, sans-serif;
		background:#F00;
		width:200px;
		height:200px;
		margin:10px;
		/*margin:10px 20px;	//取消此注释,将导致js错误*/
	}
	.show {
		border:solid 1px #000;
	}
</style>
<script type="text/javascript" src="js/jQuery-1.7.1.js"></script>
<script type="text/javascript">
	$(function() {
		var html = '';
		var bg = $('.demo').css('background');
		html += 'background :' + bg + '<br />';
		var bgC = $('.demo').css('backgroundColor');
		html += 'background-color :' + bgC + '<br />';
		var font = $('.demo').css('font');
		html += 'font :' + font + '<br />';
		var fontS = $('.demo').css('fontSize');
		html += 'font-size :' + fontS + '<br />';
		var margin = $('.demo').css('margin');
		html += 'margin :' + margin + '<br />';
		var marginT = $('.demo').css('marginTop');
		html += 'margin-top :' + marginT + '<br />';
		
		$('.show').html(html);
	})
</script>
</head>

<body>
<div class="demo">哈哈哈哈哈哈哈哈哈哈哈哈哈哈</div>
<div class="show"></div>
</body>
</html>


ie下

background :undefined
background-color :#f00
font :undefined
font-size :12px
margin :10px
margin-top :10px


chrome下

background :rgb(255, 0, 0) none repeat scroll 0% 0% / auto padding-box border-box
background-color :rgb(255, 0, 0)
font :normal normal normal 12px/24px Verdana, Geneva, sans-serif
font-size :12px
margin :10px
margin-top :10px


阅读更多
个人分类: JQuery
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭