您可以刪除script
標簽,然后檢查塊是否為空。 如果允許,則在廣告代碼之后投放的代碼中:
var blocks = $(".contentBlock");
blocks.find("script").remove();
blocks.each(function() {
var div = $(this);
if (!div.html().trim()) {
div.remove();
}
});
或者,如果您喜歡鏈接很多:
$(".contentBlock")
.find("script")
.remove()
.end()
.each(function() {
var div = $(this);
if (!div.html().trim()) {
div.remove();
}
});
如果您必須支持過時的瀏覽器,請使用$.trim()
而不是本機的String.prototype.trim
(或對其進行$.trim()
)。