博客测试
来源:互联网 发布:淘宝手机店怎么开 编辑:程序博客网 时间:2024/06/06 10:39
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>js01_hello</title><meta name="author" content="Administrator" /><script type="text/javascript">function getAllH1() {var ah = document.getElementsByTagName("h1");for(var i=0;i<ah.length;i++) {// //获取节点中的文本内容// alert(ah[i].innerHTML);// //获取节点的名称// alert(ah[i].nodeName);// //获取节点的类型// alert(ah[i].nodeType);// //获取节点中的值:节点中的值只是在针对文本节点时有用// alert(ah[i].nodeValue);// //获取某个节点的文本节点// alert(ah[i].firstChild.nodeType);//获取某个文本节点的值,对于IE和firefox而言文本的空格不一致,对于IE而言,仅仅只会把换行加入空白,但是FF而言就是全部空格//所以在获取文本节点值的时候,需要把空格去除alert("|"+ah[i].firstChild.nodeValue+"|");}}function getConH2() {var con = document.getElementById("content");var h2 = con.getElementsByTagName("h2");//得到的h2元素是一个数组alert(h2[0].innerHTML);//通过h2这个节点来找到h3中span的值//1、找到父节点var pn = h2[0].parentNode;//2、通过父节点找到名称为h3的节点var h3 = pn.getElementsByTagName("h3")[0];//3、通过h3找到spanvar s = h3.getElementsByTagName("span")[0];alert(s.innerHTML);}</script></head><body><div id="content"><h1>aaaaa1<span>aaaaassss</span></h1><h2>bbbbbbbbb1<span>bbbbbssss</span></h2><h3>cccccccc1<span>ccccccssss</span></h3></div><h1>hhhhhhhaaaaa1<span>hhhhhhhhhhhaaaaassss</span></h1><h2>hhhhhhhhhhbbbbbbbbb1<span>hhhhhhbbbbbssss</span></h2><h3>hhhhhhhhhhhcccccccc1<span>hhhhhhhhhhhhhccccccssss</span></h3><input type="button" value="获取所有的h1" onclick="getAllH1()" /><input type="button" value="获取content的h2" onclick="getConH2()" /></body></html>
0 0
- 测试博客测试博客
- 测试博客
- 测试博客
- 测试博客
- 测试博客
- 测试博客
- 测试博客
- 博客测试
- 博客测试
- 测试博客
- 测试博客
- 测试博客
- 博客测试
- 测试博客
- 测试博客
- 测试博客
- 测试博客
- 测试博客
- [Hadoop]Hadoop Archives
- 数据结构与算法(C语言版)__链式队列
- 为什么 .NET 的反射这么慢?
- 建立自己的私有云储存服务【ownCloud】
- 智能指针使用-share_ptr实例
- 博客测试
- 二维码Data Matrix编码、解码使用举例
- [POJ3415]Common Substrings(后缀数组+单调栈)
- 使用GitHub部署网站
- 欢迎使用CSDN-markdown编辑器
- linux延时函数
- text控件限制长度
- iOS - Swift CocoaPods导入OC第三方库
- Maximum Subarray