2012-01-08 102 views
1

我有這樣的代碼:jQuery對象不支持此屬性或方法

$(function() { 
if ($("div#ProductDetail_ProductDetails_div2 table tbody tr").text().trim() == '') { 
    $("div#ProductDetail_ProductDetails_div2").css("border", "0px"); 
    $("div#ProductDetail_ProductDetails_div").css({'border-bottom-left-radius' : '5px', '-moz-border-bottom-left-radius' : '5px', '-webkit-border-bottom-left-radius' : '5px', 'border-bottom-right-radius' : '5px', '-moz-border-bottom-right-radius' : '5px', '-webkit-border-bottom-right-radius' : '5px'}); 
} 
}); 

基本上,它說,如果沒有嵌套在<tr>裏面的內容,運行一些CSS修改...

然而,在IE8的調試控制檯它說在這條線上if ($("div#ProductDetail_ProductDetails_div2 table tbody tr").text().trim() == '') {「對象不支持此屬性或方法」我不知道這意味着什麼。

這對網站上的其他jQuery造成了一些問題。我知道,當我發表評論時,該網站完美運作。有人可以告訴我什麼是錯誤的IE瀏覽器抱怨的代碼?謝謝。

+0

這意味着正是它說。問題是不支持_which_屬性或方法。所以它只是簡單地知道答案,但你真的應該學會自己調試這些微不足道的問題。 – 2012-01-08 00:34:51

回答

5

jQuery的微調功能是這樣

jQuery.trim(str) 

,你可能需要獲得TD文本值進行比較。

更改像這樣

if ($.trim($("div#ProductDetail_ProductDetails_div2 table tbody tr td:first").text())=="") 
{ 
// Rest of the code 

http://api.jquery.com/jQuery.trim/

+0

他是對的。我沒有仔細看他的代碼。好電話Shyju。 +1 – 2012-01-08 00:35:16

+0

沒有'​​',這就是爲什麼'.trim()'在那裏擺在首位 – henryaaron 2012-01-08 00:48:43

相關問題