我正在研究一個page,我在其中動態創建一個Facebook Like按鈕,當用戶單擊一個圖片圖標時。 (由於頁面上有很多項目,如果我沒有這樣做,頁面加載就會嚴重抓取。)。jquery not()has()
如果我螢火蟲中運行以下命令:
var $clickTrackerGroup= $("#click-tracker-91");
console.log ($(".user-message-block", $clickTrackerGroup).html());
if ($(".user-message-block:has(div.hbo-message_likeBtn)", $clickTrackerGroup)) {
console.log("this group DOES NOT have an iframe");
} else {
console.log("this group DOES have an iframe");
}
我得到這個:
<div class="image-container">
<img src="http://graph.facebook.com/1422524707/picture" id="person-222-clicked" alt="AMANDA H" title="AMANDA H" width="50px" height="50px"></div>
<div class="user-message">
<span class="message-text">
"ipsum lorem....."</span>
<div class="message-create-time">
<span class="create-time">1/28/2011 7:33:17 AM</span>
<span class="user-name"> - Amanda H.</span>
</div>
</div>
<div class="hbo-message_likeBtn">
<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.honeybunchesofoats.com%2FBunchesOfLove.aspx%2FMessage%2F250&layout=standard&show_faces=false&width=250&action=like&colorscheme=light&height=35"
style="border: medium none ; overflow: hidden; width: 250px; height: 35px;" allowtransparency="true"
frameborder="0" scrolling="no"></iframe>
</div>
this group does not have an iframe
我也試過:
if ($(".user-message-block:has(iframe)", $clickTrackerGroup)) {
console.log("this group DOES have an iframe");
} else {
console.log("this group DOES NOT have an iframe");
}
你可以清楚地看到,HTML的此塊事實上,它有一個iframe。
如何成功測試此元素的存在?
感謝, 斯科特
是的,這個工程。留言Merci!我可以發誓,我嘗試了很多次迭代之前,但謝謝。 – Scott 2011-03-14 21:58:09
@Scott:不客氣:) – 2011-03-14 21:58:39