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 ...
随机推荐
- asp.net MVC Razor 语法(3)
编程逻辑:执行基于条件的代码. If 条件 C# 允许您执行基于条件的代码. 如需测试某个条件,您可以使用 if 语句.if 语句会基于您的测试来返回 true 或 false: if 语句启动代码块 ...
- web - 块元素和内嵌元素的特征
块: 1.独占一行 2.支持所有的样式 3.不设置宽度的时候,宽度撑满整行 常用的快标签有: div,section,header,nav,footer,article,aside,ul,ol,li, ...
- JavaScript之JS的执行环境和作用域
一.执行环境是JavaScript中最为重要的一个概念.执行环境定义了变量或函数有权访问的其他数据,决定了他们各自的行为,每个执行环境都有一个与之关联的变量对象(variable object),环境 ...
- JavaScript之向文档中添加元素和内容的方法
一.非DOM方法添加 1.document.write() <html xmlns="http://www.w3.org/1999/xhtml"> <head&g ...
- MailBee的简单使用
保存为Eml文件方法:MailMessage.SaveMessage() 读取文件方法(不知道是不是我用的问题,没找到直接读取Eml文件的方法): MsgConvert conv = new MsgC ...
- English - according to 的用法说明
1. 用于according to,意为“根据”,为复合介词,后接名词或代词.注意以下用法: (1) 主要用来表示“根据”某学说.某书刊.某文件.某人所说等或表示“按照”某法律.某规定.某惯例.某情况 ...
- JavaScript知识(一)
首先想为大家分享两句话: 侧耳听智慧,专心求聪明,呼求明哲,扬声求聪明.——箴言2:2-3 你要保守你心,胜过保守一切,因为一生的果效,是由心发出.——箴言 4:23 ...O(∩_∩)O...今天学 ...
- notepad++ 必装插件
nppftp ;FTP客户端,你懂的: explorer:设置常用文件链接:打开当前文件路径:
- Oracle查询表结构的常用语句
1. 查询表结构基本信息 select * from user_tables t,user_tab_comments c where c.table_name = t.table_name and t ...
- Mybatis设置自增主键
useGeneratedKeys="true" keyProperty="id" 方法1: <insert id="insert" p ...