2010-08-19 53 views
1

這裏是代碼:JQuery的CSS在IE 6中失敗,8

<script type="text/javascript"> 
    function doit(){ 
     $('table td').each(function() { 
     if ($(this).text().trim() != '') 
      $(this).css("border", "1px groove white"); 
     }); 
    } 
    doit(); 
</script> 

這部作品在Chrome和Firefox。 但在IE 6和8我有'對象不支持這個屬性或方法'

回答

3

這個問題是不是與.css(),但與.trim()。 IE沒有String的本地.trim()方法。

您可以改用jQuery的$.trim()

$.trim($(this).text()) 

所以if()說法是:

if ($.trim($(this).text()) != '') 
    $(this).css("border", "1px groove white"); 
+0

OMG。浪費了2個小時。謝謝!!!!! – eba 2010-08-19 13:36:15

+0

@eba - 不客氣。 :O) – user113716 2010-08-19 13:36:53