您可以删除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()
)。