firstChild属性和lastChild属性更加的语义化,而且代码更加的简洁,方便我们记忆; 注意:firstChild和lastChild只能对单个节点就行操作,不能对节点数组进行操作; 2.nodeValue 属性 作用:如果我们想改变一个文本节点的值,那就是用DOM提供的nodeValue属性,它是用来得到(和设置)一个文本节点的值; 如下代码: <body>
hello /p> <script type="text/javascript"> var p = document.getElementById("description"); alert(p.nodeValue 值是一个null值,而且最重要的是nodeValue属性是用来获取文本节点的值的。 ); </script> </body> 学完nodeValue属性后我们能给我们的JS图片库加一个新的功能。
;
document.getElementById("from").innerHTML=xmlDoc.getElementsByTagName("from")[0].childNodes[0].nodeValue ("YEAR")[0].childNodes[0].nodeValue);
txt="Artist: " + artist + "
Title: " + title + "
Year ("YEAR")[0].childNodes[0].nodeValue);
country=(x[i].getElementsByTagName("COUNTRY")[0].childNodes [0].nodeValue);
company=(x[i].getElementsByTagName("COMPANY")[0].childNodes[0].nodeValue);
price =(x[i].getElementsByTagName("PRICE")[0].childNodes[0].nodeValue);
txt="Artist: "+artist+"
Title
//Note: (1)元素节点的NodeValue null //Note: (2)属性节点的NodeValue 是属性值 //Note: (3)注释节点的NodeValue 是注释的内容 //Note: (1)文本节点的NodeValue 是文本本身 //Note: (1)文档节点的NodeValue null console.debug("NodeValue"); console.log ("Element NodeValue : " + testDomDiv.nodeValue); console.log("Attribute NodeValue: "+ newAttribute.nodeValue ); console.log("Comment NodeValue : " + createComment.nodeValue); console.log("Text NodeValue : " + createTextNode.nodeValue); console.log("Document NodeValue : " + document.nodeValue); 看一下浏览器上的输出结果
判断xss的方法为: 1、 监听页面的弹窗事件 2、 查看dom中的localName是否有存在我们自定义的标签 3、 查看dom中的nodeValue 是否含有我们输入的payload 将其分为三个等级 nodeId":30454,"parentId":30453,"backendNodeId":7,"nodeType":1,"nodeName":"HTML","localName":"html","nodeValue nodeId":30455,"parentId":30454,"backendNodeId":8,"nodeType":1,"nodeName":"HEAD","localName":"head","nodeValue nodeId":30456,"parentId":30454,"backendNodeId":9,"nodeType":1,"nodeName":"BODY","localName":"body","nodeValue [{"nodeId":30459,"parentId":30458,"backendNodeId":12,"nodeType":1,"nodeName":"TR","localName":"tr","nodeValue
节点属性 在DOM中,每一个节点都是一个对象,DOM节点有三个重要的属性: nodeName: 节点的名称 nodeValue: 节点的值 nodeType: 节点的类型 以这段html为例 <body 获取节点的值 nodeName 属性获取节点的值 元素节点的 nodeValue 是 undefined 或 null 文本节点的 nodeValue 是文本本身 属性节点的 nodeValue 是属性值 element = document.getElementById('demo') // 元素节点的 nodeName 与标签名相同 console.log(element.nodeValue console.log(element.childNodes[0].nodeValue); // Hello world! // 文档节点 console.log(document.nodeValue); // null nodeType 节点类型 节点的类型,只读,对照这张表 元素类型 节点类型 元素 1 属性
DOM 节点有三个重要的属性 :
1. nodeName : 节点的名称
2. nodeValue :节点的值
3. nodeType :节点的类型
一、nodeName 文档节点的 nodeName 永远是 #document
二、nodeValue 属性:节点的值
1. 元素节点的 nodeValue 是 undefined 或 null
2. 文本节点的 nodeValue 是文本自身
3. 属性节点的 nodeValue 是属性的值
三、nodeType 属性: 节点的类型,是只读的。以下常用的几种结点类型:
元素类型 节点类型
! document.write("1:li节点的类型—【文档】—
");
break;
}
document.write("2:li里边的文本内容——"+m[i].nodeValue
;
document.getElementById("from").innerHTML=xmlDoc.getElementsByTagName("from")[0].childNodes[0].nodeValue ("YEAR")[0].childNodes[0].nodeValue);
txt="Artist: " + artist + "
Title: " + title + "
Year ("YEAR")[0].childNodes[0].nodeValue);
country=(x[i].getElementsByTagName("COUNTRY")[0].childNodes [0].nodeValue);
company=(x[i].getElementsByTagName("COMPANY")[0].childNodes[0].nodeValue);
price =(x[i].getElementsByTagName("PRICE")[0].childNodes[0].nodeValue);
txt="Artist: "+artist+"
Title
DOCTYPE html> 文档片段节点 DocumentFragment 11 Javascript obj.nodeName obj.nodeValue obj.attributes[0 ].nodeName | nodeValue // 获取元素节点值及属性值 obj.childNodes[0].nodeName | nodeValue // 获取文本节点值及文本值 document.doctype.nodeName | nodeValue // 获取文档类型节点值及类型
= "00:00:0"+t; }else if(t>=10&&t<60){ txt.nodeValue = "00:00:"+t; }else var t1 = t%60; if(m<10){ if(t1<10){ txt.nodeValue = "00:0"+m+":0"+t1; }else if(t1>=10&&t1<60){ txt.nodeValue = "00 = "00:"+m+":0"+t1; }else if(t1>=10&&t1<60){ txt.nodeValue = "00: (t1>=10&&t1<60){ mt = m+":"+t1; } } txt.nodeValue
element.attributes();然后循环挨个取出名称和值即可,QDomNode n = attrs.item(i);QString nodeName = n.nodeName();QString nodeValue = n.nodeValue(); 二、实现的功能 自动加载插件文件中的所有控件生成列表,默认自带的控件超过120个。 = n.nodeValue(); //qDebug() << nodeName << nodeValue; //优先取出坐标 (); } else if (nodeName == "y") { y = nodeValue.toInt(); } else if (nodeName == "width") { width = nodeValue.toInt
针对三种节点分别从nodeType、nodeName和nodeValue三个方面进行区分比较: nodeType: 元素节点:1 属性节点:2 文本节点:3 对于nodeName以及 nodeValue根据不同的情况值也不同,下面举一个例子: 1.元素节点: 1 <HTML> 2 <HEAD> 3 <TITLE>区分nodeName和nodeValue</TITLE> ) ; 16 </script> 17 </BODY> 18 </HTML> 运行结果为: nodeType:1 nodeName:td nodeValue:null 2.属性节点: 1 <HTML> 2 <HEAD> 3 <TITLE>区分nodeName和nodeValue</TITLE> 4 </HEAD> 5 <BODY ) ; 16 </script> 17 </BODY> 18 </HTML> 运行结果如下: nodeType:2 nodeName:name nodeValue:
(node.nodeType === 3) { // 如果是文本节点,就通过正则放回匹配的结果 const result_regexp = pattren.exec(node.nodeValue 替换成实际的值 const attr = result_regexp[1]; node.nodeValue = node.nodeValue.replace(pattren $data) node.nodeValue = node.nodeValue.replace(pattren, replaceVal ); // ... } 刷新浏览器之后发现我们的数据已经渲染完成了 ); const value = attr.nodeValue .split(".") .reduce((prev, current) ); const value = attr.nodeValue .split(".") .reduce((prev, current)
node.cloneNode(true//深复制) HTMLDocument类型 document.nodeType = 9 document.nodeName = “#document” document.nodeValue 类型 var elem = document.getElementById(‘elem_id’); elem.nodeType = 1 elem.nodeName 为元素的标签名 elem.nodeValue world var text\_node = div.firstChild; var text\_node = document.createTextNode(text); text_node.nodeValue (offset); text_node.substringData(offset); text_node.length = text_node.data.length = text_node.nodeValue.length 中的节点 var attr = document.createAttribute(attr_name); attr.nodeType = 11 attr.nodeName 属性名 attr.nodeValue
---- nodeValue 属性 nodeValue 属性规定节点的值。 元素节点的 nodeValue 是 undefined 或 null 文本节点的 nodeValue 是文本本身 属性节点的 nodeValue 是属性值 ---- 获取元素的值 下面的例子会取回 <p
<script> x=document.getElementById("intro"); document.write(x.firstChild.nodeValue); </script>in task.childNodes: # print('line.nodeName:',line.nodeName,'line.nodeType:',line.nodeType,'line.nodeValue :',line.nodeValue,'line.normalize:',line.normalize) # print(len(line)) # print(line) if 3 # if 3 == tmp2.nodeType: # continue print(tmp2.nodeValue .childNodes: # if 3 == line2.nodeType: # continue # print(line2.nodeValue
表示元素的属性节点,3表示文本节点 2)nodeName,元素节点的nodeName是元素标签,文本节点的nodeName是#Text,Document的nodeName是 #document 3)nodeValue ,元素和Document的nodeValue都是null,文本节点的nodeValue是纯文本,属性节点的 nodeValue是属性值 节点关系:childNodes,parentNode,firstChild
对于文本节点,nodeValue值为文本值 对于属性节点,nodeValue值为属性值 <body>
段落
<script type="text/javascript"> var 返回值"+element.nodeValue); console.log("文本节点nodeValue返回值"+text.nodeValue); console.log("属性节点nodeValue返回值 "+property.nodeValue); console.log("文档节点nodeValue返回值"+document.nodeValue); </script> </body> </html> :'+text.nodeValue); //文本节点的nodeValue是其文本内容 text.nodeValue=text.nodeValue+"abc"; //文本内容添加修改删除等等。 其他节点使用nodeValue。var oPre = oNext.previousElementSibling; alert(oFirst.firstChild.nodeValue ); alert(oLast.firstChild.nodeValue); alert(oNext.firstChild.nodeValue); alert(oPre.firstChild.nodeValue
nodeValue 属性返回文本节点的文本值。 ;XML DOM 更改节点值nodeValue 属性用于更改节点的值。 更改文本节点的值nodeValue 属性可用于更改文本节点的值。 循环遍历所有 <title> 元素并添加使用 nodeValue 更改属性nodeValue 属性是属性节点的值。更改 value 属性会更改属性的值。 可以使用 nodeValue 属性代替。请参阅下一段。
("del.xml") #打开xml文档 root = dom.documentElement #得到xml文档 print("nodeName:",root.nodeName) # print("nodeValue :",root.nodeValue) print("nodeType:",root.nodeType) print("ELEMENT_NODE:",root.ELEMENT_NODE) #2、获得子标签 = root.getElementsByTagName('maxid') print(type(bb)) print(bb) b = bb[0] print(b.nodeName) print(b.nodeValue # # node.childNodes[index].nodeValue # 获取XML节点值 # # node.firstChild # # 访问第一个节点。 等价于pagexml.childNodes[0] 3、运行的结果如下 #1、获得标签属性 nodeName: catalog nodeValue: None nodeType: 1 ELEMENT_NODE