2011-11-21 110 views
0

我試圖編寫一個jQuery滑塊。我有一個html代碼,看起來像這樣。我早些時候發佈了一個更簡單的代碼版本,以便這個問題看起來不會太長。對帶來的麻煩表示抱歉。下面是實際的代碼Jquery.find()在ie中返回null,但在其他瀏覽器中不返回

<div class="allItems"> 
    <div class="echItm"> 
     <h4>asdddddddd </h4> 
     <span class="mImg">/web/images/promotionSlideShowImages/kc1g358wvv.jpg</span> 
     <span class="tImg">/web/images/promotionSlideShowThumbnailsNew/kc1g358wvv.gif</span> 
    </div> 

    <div class="echItm"> 
     <h4>dddddddddd </h4> 
     <span class="mImg">/web/images/promotionSlideShowImages/ptvrbfpnkd.jpg</span> 
     <span class="tImg">/web/images/promotionSlideShowThumbnailsNew/ptvrbfpnkd.gif</span> 
    </div> 
</div> 

當我嘗試使用

var imagesArray=$('.allItems').find('.echItm'); 
    for(var i=0;i<imagesArray.length;i++){ 
    var thisElement=imagesArray[i]; 
    alert($(thisElement).html()); 
} 

IE返回null,而火狐,Chrome返回所需的HTML做一個查找。有人能指導我,我做錯了什麼?我正在使用Jquery 1.4.2並在IE8上進行測試。提前致謝。

+0

好像有可能是這裏的解決方案: http://stackoverflow.com/questions/562283/jquery-find-doesnt-return-data-in-ie-but-does-in-firefox -and-chrome –

+1

您使用的是哪個IE版本?我已經[在IE7上運行你的代碼](http://jsfiddle.net/7DLex/)沒有問題。 – OnesimusUnbound

+0

看起來這可能是相同的問題: http://stackoverflow.com/questions/562283/jquery-find-doesnt-return-data-in-ie-but-does-in-firefox-and -chrome –

回答

4

testElement已經是jQuery對象,因此您不必將其包裝在$()中。試試這個

var testElement=$('.echItm').find('h4'); 
alert(testElement.html()); 
+0

試過... IE仍然返回null,而Firefox也可以正常使用這個代碼... –

+1

你可以檢查在頁面上呈現的IE中的源代碼。我認爲這個標記可能沒有很好的形成,所以這個問題是在IE中出現的,對於糟糕的標記不好。 – ShankarSangoli

+0

我編輯了這個問題。我也在IE中檢查了這個標記,它格式正確 –

3

看起來好像this可能是同一個問題。

它與IE的更嚴格的XML/Mimetype解析有關。

+0

今天剛剛遇到這個問題 - 上面的鏈接指出了潛在的問題,並且應該可能是這裏接受的答案。 – Phantomwhale

相關問題