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 ...
随机推荐
- swift论坛正式上线
www.iswifting.com swift论坛正式上线.有问答专区,也有技术分享区,还有学习资料区,大家一起学习成长! 2014中国互联网大会于8月26日开幕. 政府主管部门.行业专家.企业领袖将 ...
- poj 1469(二分图 最大匹配)
这道题让我认识到了c++cin,cout确实会使其超时,还是我用的c printf吧 #include<cstdio> #include<iostream> #include& ...
- 一周学会Mootools 1.4中文教程:(6)动画
先看一下动画的参数设置: 参数: fps - (number:默认是50) 每秒的帧数. unit - (string:默认是 false) 单位,可为 'px','em',或 '%'. link - ...
- android中ScrollView和GridView/ListView共存时,ScrollView不在顶部的解决方法
listView.setFocusable(false); gridView.setFocusable(false); 这个必须在代码中写,xml文件中设置不起作用 原文:http://stackov ...
- 为什么Java项目前会出现一个红色感叹号!
先看看问题,如下图所示: 造成这个问题的原因是,我把一个 jar 包删除了,然后又配了个新的进去,然后就一直有这个错误,刚开始很郁闷,怎么已经配置过儿,还出现这个问题?关键是代码里面没有报错的.郁闷的 ...
- 从头编译ARM交叉编译环境
首先Cygwin需安装基本的命令 例如make binutils gcc 还有diffutils 没有他会报找不到cmp命令 这些都可以在setup.exe中找到 编译gcc时,需要注意一个原则:不要 ...
- 美版nexus 5 LG D820才支持CDMA,国际版LG D821不支持
我们都知道nexus 5其实是有两个不同的版本的,分别是LG D820和LG D821,它们在几乎所有的配置和外观上都没有任何的区别,主要区别在通讯模块上,一个支持GSM/CDMA/WCDMA/LTE ...
- Html 小插件7 新闻免费代码
http://rss.cnfol.com/freecode/ 定制方法图:
- [置顶] C++基础之六:运算符的重载
网上太多有关运算符的重载了,但是写的太过的详细,不适合新手入门,特别是那什么++和--的前增量后增量重载,一元二元运算符重载,特殊运算符,下标运算符,new和delete,甚至是指针运算符的重载,吓退 ...
- Spring 上下文
Spring 上下文WebApplicationContext.是服务器启动的时候加载ContextLoaderListener 的时候存在 ServletContext 中 servletConte ...