javascript Node操作
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
</head>
<script type="text/javascript">
window.onload=function(){
var ul=document.getElementsByTagName('ul')[0];
//console.log(ul.nodeName);//UL
var lis=ul.childNodes;
for (var i = 0; i < lis.length; i++) {
console.log('the '+i+'th node is '+lis[i].nodeName);
}
//the 0th node is #text
// the 1th node is LI
// the 2th node is #text
// the 3th node is LI
// the 4th node is #text
// the 5th node is LI
// the 6th node is #text
ul=document.getElementsByTagName('ul')[1];
lis=ul.childNodes;
for (var i = 0; i < lis.length; i++) {
console.log('the '+i+'th node is '+lis[i].nodeName);
}
// the 0th node is LI
// the 1th node is LI
// the 2th node is LI
//很明显 回车也会被认为是一个Node
//所以应该这么处理
ul=document.getElementsByTagName('ul')[0];
lis=ul.childNodes;
for (var i = 0; i < lis.length; i++) {
if(lis[i].nodeType==1){
console.log('the '+i+'th node is '+lis[i].nodeName);
}
}
// the 1th node is LI
// the 3th node is LI
// the 5th node is LI }
</script>
<body>
<ul>
<li>li1</li>
<li>li2</li>
<li>li3</li>
</ul> <ul><li>li1</li><li>li2</li><li>li3</li></ul> </body>
</html>
javascript Node操作的更多相关文章
- javascript DOM 操作
在javascript中,经常会需要操作DOM操作,在此记录一下学习到DOM操作的知识. 一.JavaScript DOM 操作 1.1.DOM概念 DOM :Document Object Mode ...
- JavaScript 节点操作Dom属性和方法(转)
JavaScript 节点操作Dom属性和方法 一些常用的dom属性和方法,列出来作为手册用. 属性: 1.Attributes 存储节点的属性列表(只读) 2.childNodes 存储 ...
- Node操作MongoDB并与express结合实现图书管理系统
Node操作MongoDB数据库 原文链接:http://www.xingxin.me/ Web应用离不开数据库的操作,我们将陆续了解Node操作MongoDB与MySQL这是两个具有代表性的数据库, ...
- javascript DOM 操作基础知识小结
经常用到javascript对dom,喜欢这方便的朋友也很多,要想更好的对dom进行操作,这些基础一定要知道的. DOM添加元素,使用节点属性 <!DOCTYPE html PUBLIC ...
- Redis的C++与JavaScript访问操作
上篇简单介绍了Redis及其安装部署,这篇记录一下如何用C++语言和JavaScript语言访问操作Redis 1. Redis的接口访问方式(通用接口或者语言接口) 很多语言都包含Redis支持,R ...
- javascript DOM 操作 attribute 和 property 的区别
javascript DOM 操作 attribute 和 property 的区别 在做 URLRedirector 扩展时,注意到在使用 jquery 操作 checkbox 是否勾选时,用 at ...
- select元素javascript常用操作 转
/*------------------------------------------------------ *作者:xieyu @ 2007-08-14 *语言:JavaScript *说明:s ...
- javascript DOM操作之 querySelector,querySelectorAll
javascript DOM操作之 querySelector,querySelectorAll
- JavaScript动态操作style
1.易错:修改元素的样式不是设置class属性,而是className属性.class是JS的一个保留关键字. 2.易错:单独修改样式的属性使用"style.属性名"3.注意在cs ...
随机推荐
- 自己写的sql server触发器练练--高手请您跳过吧
set ANSI_NULLS ONset QUOTED_IDENTIFIER ONgo ALTER TRIGGER [insertReplyToic] ON [dbo].[bbsReplyTopic] ...
- 查询离指定日期最近的一条数据(oracle)
select * from ( Select * from t_currency_rate where f_orig_curr='USD' and f_dest_curr='RMB ...
- 基于HTTP协议下载文件的实现
最近在开发文件下载的程序,该程序是基于HTTP开发的. 首先是了解了文件传输到客户端的大概格式,然后分析该格式,实现写入文件的功能. 自己构造的HTTP包如下: GET /*********.rar ...
- linux杂记(?)命令别名——alias
linux中的命令别名--alias linux中的命令别名--alias 1. 用命令alias可以查询系统中有哪些可用的命令别名 2.添加命令别名 回车查看, 别名建立成功 3.查询命令的地址ty ...
- R与数据分析旧笔记(五)数学分析基本
R语言的各种分布函数 rnorm(n,mean=0,sd=1)#高斯(正态) rexp(n,rate=1)#指数 rgamma(n,shape,scale=1)#γ分布 rpois(n,lambda) ...
- Hadoop学习笔记01——Hadoop分布式文件系统
Hadoop有一个称为HDFS的分布式系统,全称为Hadoop Distributed Filesystem. HDFS有块(block)的概念,默认为64MB,HDFS上的文件被划分为块大小的多个分 ...
- zoj 2587 Unique Attack 最小割判定
题目链接 让你判断最小割是否唯一. 判断方法是, 先求一遍最大流, 然后从源点dfs一次, 搜索未饱和边的数目. 从汇点dfs一次, 同样也是搜索未饱和边的数目, 看总和是否等于n. 如果等于n那么唯 ...
- MySQL学习系列一---命令行连接mysql和执行sql文件
1.命令行连接mysql #mysql -h(主机) -u(用户名) -p (数据库名) mysql -hlocalhost -uroot -p testdb Enter password: **** ...
- python基础学习笔记5--对象方法、属性和迭代器
对象方法.属性和迭代器 1.构造方法 1)构造方法和一般方法的不同点:当一个对象被创建后,会立即调用构造方法. 2)在Python中创建一个构造方法很容易,只要把init方法的名字从简单的init修改 ...
- JAVA并发,CountDownLatch使用
该文章转自:http://www.itzhai.com/the-introduction-and-use-of-a-countdownlatch.html CountDownLatch 1.类介绍 一 ...