Javascript 如何向非';不受限制
这是本书的延续 这样,Javascript 如何向非';不受限制,javascript,jquery,Javascript,Jquery,这是本书的延续 这样,父节点仍然可见,但非安全区域消失,留下安全 我不知道该怎么做,但肯定是有可能的。匹配h1的所有内容,并使用.not()从您的选择中删除safe。然后使用.wrap()使它们“消失” 文本节点的节点类型为3。迭代节点并使用wrap()包装文本节点: $someElement.contents().each(function() { if (this.nodeType == 3) $(this).wrap('<span class="disappe
父节点
仍然可见,但非安全
区域消失,留下安全
我不知道该怎么做,但肯定是有可能的。匹配
h1
的所有内容,并使用.not()
从您的选择中删除safe
。然后使用.wrap()
使它们“消失”
文本节点的
节点类型为3。迭代节点并使用wrap()
包装文本节点:
$someElement.contents().each(function() {
if (this.nodeType == 3)
$(this).wrap('<span class="disappear" />');
});
$someElement.contents().each(函数()){
if(this.nodeType==3)
$(此).wrap(“”);
});
过滤文本节点并将其包装为跨距:
$('h1').contents().filter(function() {
return this.nodeType === 3;
}).wrap('<span class="disappear" />');
$('h1').contents().filter(函数(){
返回this.nodeType==3;
}).wrap(“”);
@JasonP-谢谢,基本上是一样的,只是用filter()而不是each()进行迭代。
$someElement.contents().each(function() {
if (this.nodeType == 3)
$(this).wrap('<span class="disappear" />');
});
$('h1').contents().filter(function() {
return this.nodeType === 3;
}).wrap('<span class="disappear" />');
$('h1').children().not('.safe').hide();