我擁有包含imgs的div。但是,這些div中的一些也具有跨度作爲div內的第一個元素。此跨度代表此div內imgs的「標籤」。如果容器擁有某個類別的div,請從容器中移除img
我有一個腳本去如果我按住ALT並點擊這個'包'div,它會被刪除。但是,我不想刪除包含標籤的數據包。對於那些,只刪除內部的img就足夠了。
我在建立邏輯時遇到了麻煩。同時,通過點擊並按住alt鍵來傳達刪除的能力,我試圖讓一個css屬性改變一些顏色作爲提示。這也是行不通的。
$(".Card_Packet").click(function (e) {
if (e.altKey) {
$(this).live('hover', function(event) {
if (event.type === 'mouseover') {
$(this).css({
'border-color': 'red'
});
}
else {
$(this).css({
'border-color':'black'
});
}
});
if ($(this).find('Sect_Header')) { //if the div contains the label, remove only the images. Otherwise, remove the whole thing.
$(this).remove('img');
} else {
$(this).remove();
}
}
});
我確定它與我的操作順序有關。
定義「不工作」 – Alnitak 2011-04-11 21:27:27
應該是'.find(「 Sect_Header」)'的點缺 – Adam 2011-04-11 21:29:23
什麼是‘Sect_Header’?它看起來像你正在尋找一個標籤名稱爲'Sect_Header'的元素。 – ChrisThompson 2011-04-11 21:31:20