<!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操作的更多相关文章

  1. javascript DOM 操作

    在javascript中,经常会需要操作DOM操作,在此记录一下学习到DOM操作的知识. 一.JavaScript DOM 操作 1.1.DOM概念 DOM :Document Object Mode ...

  2. JavaScript 节点操作Dom属性和方法(转)

    JavaScript 节点操作Dom属性和方法   一些常用的dom属性和方法,列出来作为手册用. 属性:   1.Attributes 存储节点的属性列表(只读)   2.childNodes 存储 ...

  3. Node操作MongoDB并与express结合实现图书管理系统

    Node操作MongoDB数据库 原文链接:http://www.xingxin.me/ Web应用离不开数据库的操作,我们将陆续了解Node操作MongoDB与MySQL这是两个具有代表性的数据库, ...

  4. javascript DOM 操作基础知识小结

    经常用到javascript对dom,喜欢这方便的朋友也很多,要想更好的对dom进行操作,这些基础一定要知道的.   DOM添加元素,使用节点属性  <!DOCTYPE html PUBLIC ...

  5. Redis的C++与JavaScript访问操作

    上篇简单介绍了Redis及其安装部署,这篇记录一下如何用C++语言和JavaScript语言访问操作Redis 1. Redis的接口访问方式(通用接口或者语言接口) 很多语言都包含Redis支持,R ...

  6. javascript DOM 操作 attribute 和 property 的区别

    javascript DOM 操作 attribute 和 property 的区别 在做 URLRedirector 扩展时,注意到在使用 jquery 操作 checkbox 是否勾选时,用 at ...

  7. select元素javascript常用操作 转

    /*------------------------------------------------------ *作者:xieyu @ 2007-08-14 *语言:JavaScript *说明:s ...

  8. javascript DOM操作之 querySelector,querySelectorAll

    javascript DOM操作之 querySelector,querySelectorAll

  9. JavaScript动态操作style

    1.易错:修改元素的样式不是设置class属性,而是className属性.class是JS的一个保留关键字. 2.易错:单独修改样式的属性使用"style.属性名"3.注意在cs ...

随机推荐

  1. Android流式布局实现

    查看我的所有开源项目[开源实验室] 欢迎增加我的QQ群:[201055521],本博客client下载[请点击] 摘要 新项目用到了一种全新布局----Android标签流式布局的功能,正好一直说给大 ...

  2. adb server is out of date.

    1:今天调试android的时候发现一个诡异的问题 C:\Users\xxxx>adb start-server adb server is out of date.  killing... A ...

  3. 权威指南学习心得-浏览器中的js

    window对象:表示web了浏览器的一个窗口或窗体(winow属性引用自身) 含有以下属性:location包含Location对象,指定当前显示在窗口中URL,允许脚本往窗口里载入新的URL 含有 ...

  4. spring mvc 返回json数据的四种方式

    一.返回ModelAndView,其中包含map集 /* * 返回ModelAndView类型的结果 * 检查用户名的合法性,如果用户已经存在,返回false,否则返回true(返回json数据,格式 ...

  5. windows8 安装IIS 和 添加网站(转)

    Internet Information Services(IIS,互联网信息服务),是由微软公司提供的基于运行Microsoft Windows的互联网基本服务.最初是Windows NT版本的可选 ...

  6. 亲测的一款在线作图神器:ProcessOn

    本人近日发现一款作图神器:ProcessOn 它是一款在线的作图工具,完全国产,前台是用HTML5  Canvas加javascript做绘图,后台用java实现数据处理和图片生成, 整站UI基本类似 ...

  7. uva 10779 Collectors Problem 网络流

    链接 一共有n个人, m种收藏品, 每个人拥有的收藏品的种类和个数都是不相同的. 假设2-n这些人都只和1互相交换, 比例是1:1, 并且, 2-n这些人, 只换自己现在没有的, 如果他现在有第二种, ...

  8. nyist 220 推桌子

    题目链接:推桌子 题目意思:给你一些操作,将S出的桌子推到L出,但是这个过道有时会被占用,推一次是10min,不影响的操作可以同时开始,并且只记一次. 思路:贪心,首先按照S从小到大排序,决策:从第一 ...

  9. Windows 8.1 正式版微软官方原版镜像下载(新增10/17新版下载)

    中文版:中国区OEM预装版本,特定国家版,锁定语言,其它功能和核心版没有区别.简体中文单语言版:锁定语言,其它功能和核心版没有区别.专业版+核心版[零售版][推荐]:镜像内包含专业版(Professi ...

  10. java selenium webdriver实战 seleniumIDE

    Selenium是ThoughtWorks公司,一个名为Jason Huggins的测试为了减少手工测试的工作量,自己实现的一套基于Javascript语言的代码库 使用这套库可以进行页面的交互操作, ...