JQuery CSS在IE 6、8中失败
以下是代码:JQuery CSS在IE 6、8中失败,jquery,css,asp.net-mvc-2,Jquery,Css,Asp.net Mvc 2,以下是代码: <script type="text/javascript"> function doit(){ $('table td').each(function () { if ($(this).text().trim() != '') $(this).css("border", "1px groove white"); }); } doit(); </scrip
<script type="text/javascript">
function doit(){
$('table td').each(function () {
if ($(this).text().trim() != '')
$(this).css("border", "1px groove white");
});
}
doit();
</script>
函数doit(){
$('table td')。每个(函数(){
如果($(this).text().trim()!=“”)
$(此).css(“边框”,“1px槽白色”);
});
}
doit();
这适用于chrome和firefox。
但在IE 6和IE 8中,我有一个“Object不支持此属性或方法”问题不在于
.css()
,而在于.trim()
。IE没有字符串的本机.trim()
方法
您可以使用jQuery的$.trim()
$.trim($(this).text())
if()
语句应该是:
if ( $.trim($(this).text()) != '' )
$(this).css("border", "1px groove white");