Javascript 仅用节点环绕文本
我有一些html的形式Javascript 仅用节点环绕文本,javascript,jquery,html,Javascript,Jquery,Html,我有一些html的形式 <span class="prefix">something</span> (Optional) Text <span class="badge">Something else</span> (optional, can be multiple) <span class="postfix">Another thing</span> filter()将容器元素的contents()转换为纯文本节点 w
<span class="prefix">something</span> (Optional)
Text
<span class="badge">Something else</span> (optional, can be multiple)
<span class="postfix">Another thing</span>
filter()
将容器元素的contents()
转换为纯文本节点wrap()
$('#容器').contents().filter(函数()){
返回$(this)[0]。nodeValue&&$(this)[0]。nodeValue.trim();
}).wrap(“”)代码>
.txt{
颜色:绿色;
}
某物
正文
别的
还有一件事
filter()
将容器元素的contents()
转换为纯文本节点
wrap()
$('#容器').contents().filter(函数()){
返回$(this)[0]。nodeValue&&$(this)[0]。nodeValue.trim();
}).wrap(“”)代码>
.txt{
颜色:绿色;
}
某物
正文
别的
还有一件事
filter()
将容器元素的contents()
转换为纯文本节点
wrap()
$('#容器').contents().filter(函数()){
返回$(this)[0]。nodeValue&&$(this)[0]。nodeValue.trim();
}).wrap(“”)代码>
.txt{
颜色:绿色;
}
某物
正文
别的
还有一件事
filter()
将容器元素的contents()
转换为纯文本节点
wrap()
$('\35;容器').contents().filter(函数(){
返回$(this)[0]。nodeValue&&$(this)[0]。nodeValue.trim();
}).wrap(“”)代码>
.txt{
颜色:绿色;
}
某物
正文
别的
还有一件事
试试这个:
$('#container').contents()
.filter(function() { return this.nodeType === 3 })
.wrap('<span class="txt" />');
$(“#容器”).contents()
.filter(函数(){返回this.nodeType==3})
.wrap(“”);
根据这个答案:试试这个:
$('#container').contents()
.filter(function() { return this.nodeType === 3 })
.wrap('<span class="txt" />');
$(“#容器”).contents()
.filter(函数(){返回this.nodeType==3})
.wrap(“”);
根据这个答案:试试这个:
$('#container').contents()
.filter(function() { return this.nodeType === 3 })
.wrap('<span class="txt" />');
$(“#容器”).contents()
.filter(函数(){返回this.nodeType==3})
.wrap(“”);
根据这个答案:试试这个:
$('#container').contents()
.filter(function() { return this.nodeType === 3 })
.wrap('<span class="txt" />');
$(“#容器”).contents()
.filter(函数(){返回this.nodeType==3})
.wrap(“”);
基于这个答案:“我希望得到一个类似这样的输出:“是否需要在现有的span
元素中使用额外的span
元素包装文本?或者,将span
元素的现有文本包含在.txt
span
?@guest271314中,以将纯文本(不在任何其他节点内)包装为新的span。“我希望得到类似以下内容的输出:”是否要求在现有的span
元素中使用附加的span
元素包装文本?或者,将span
元素的现有文本包含在.txt
span
?@guest271314中,以将纯文本(不在任何其他节点内)包装为新的span。“我希望得到类似以下内容的输出:”是否要求在现有的span
元素中使用附加的span
元素包装文本?或者,将span
元素的现有文本包含在.txt
span
?@guest271314中,以将纯文本(不在任何其他节点内)包装为新的span。“我希望得到类似以下内容的输出:”是否要求在现有的span
元素中使用附加的span
元素包装文本?或者,将span
元素的现有文本包含在.txt
span
?@guest271314中,以使用新span包装纯文本(不在任何其他节点内)。