使用jquery
选择具有JQuery的元素的后代文本节点需要一些创造力。 While jQuery does not offer a specific function for this task, it's possible to combine the methods contents() and find() to achieve the desired result.
jQuery Solutionvar getTextNodesIn = function(el) { 返回$(el).find(“:not(iframe)”)。 返回this.nodeType == 3; }); }; getTextNodesin(el);
Pure JavaScript Solutionvar getTextNodesIn = function(el) { return $(el).find(":not(iframe)").addBack().contents().filter(function() { return this.nodeType == 3; }); }; getTextNodesIn(el);
If you prefer a pure JavaScript approach, the following function can be used:
function getTextNodesIn(node, includeWhitespaceNodes) {
var textnodes = [],nonwhitespacematcher = /\ s /;
函数getTextNodes(node){
if(node.nodeType == 3){
if(包括whitespacenodes || nonwhitespacematcher.test(node.nodevalue)){
textnodes.push(node);
}
} 别的 {
for(var i = 0,len = node.childnodes.length; i
免责声明: 提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发到邮箱:[email protected] 我们会第一时间内为您处理。
Copyright© 2022 湘ICP备2022001581号-3