Blogger Information
Blog 11
fans 0
comment 0
visits 21121
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
处理html元素中的内容
玄夜的博客
Original
887 people have browsed it
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>
	<body>
		<p>我正在学习JavaScript编程技术</p>
		<p>我正在学习<strong style="color: red;">JavaScript</strong>编程技术</p>
	</body>
	
	<script>
		var p = document.getElementsByTagName('p')[0];
		var p1 = document.getElementsByTagName('p').item(1);
		console.log(p.innerHTML);   //innerHTML可以输出标签
		console.log(p1.innerHTML)
		
		//textContent   仅获取纯文本
		console.log(p.textContent);
		console.log(p1.textContent);
		
		//nodeType == 3  文本节点  
		//nodeValue  节点值
		if(p.childNodes[0].nodeType == 3){
			console.log(p.childNodes[0].nodeValue);
		}
		
		if(p1.childNodes[0].nodeType == 3){
			console.log(p1.childNodes[0].nodeValue);
		}
	</script>
</html>


Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post