首先声明的是:

document.getElementByName方法没有。document.getElementsByName得到的是标签的数组
document.getElementId得到的是某一个标签
<form name="form_write">
<input name="content" type="text">

然而可以用很浅显的方式得到如:

var fn = document.getElementsByName("form_write")[0];  //得到这个form下的对象

fn.content.value;//就直接去用这个对象取值就可以了。

document.getElementById

 
 
1、getElementById

作用:一般页面里ID是唯一的,用于准备定位一个元素 

语法: document.getElementById(id) 

参数:id :必选项为字符串(String) 

返回值:对象; 返回相同id对象中的第一个,按在页面中出现的次序,如果无符合条件的对象,则返回 null

example:

document.getElementById("id1").value;

2、getElementsByName

作用:按元素的名称查找,返回一个同名元素的数组

语法: document.getElementsByName(name)

参数:name :必选项为字符串(String)

返回值:数组对象; 如果无符合条件的对象,则返回空数组,按在页面中出现的次序

注意:返回数组值为value属性的值,
            如果某标签无value属性,当你添加上value属性并赋值后,getElementsByName也能取到其值,
            当未对value属性赋值时,  getElementsByName返回数组值将是undefined ,
            但仍能获得相同name标签的个数document.getElementsByName(name).length
            当未设置name属性时document.getElementsByName仍能使用,它将根据你id取得value属性的值

example:

document.getElementsByName("name1")[0].value;  

document.getElementsByName("name1")[1].value;

<span id='CBylawIndexName' class='normalNode' value='all' >全部</span>"
<span id='CBylawIndexName' class='normalNode' value='ALL' >全部</span>"

span标签其实没有name和value属性
但document.getElementsByName("CBylawIndexName")仍将取得value的值

3、getElementsByTagName

作用:按HTML标签名查询,返回一个相同标签元素的数组

语法: object.getElementsByTagName(tagname) object可以是document或event.srcElement.parentElement等

参数:tagname:必选项为字符串(String),根据HTML标签检索。

返回值:数组对象; 如果无符合条件的对象,则返回空数组,按在页面中出现的次序

example:

document.getElementsByTagName("p")[0].childNodes[0].nodeValue;  

document.getElementsByTagName("p")[1].childNodes[0].nodeValue

没有document.getElementByName的更多相关文章

  1. Windows.document

    一.找到元素: document.getElementById("id");根据id找,最多找一个 var a =document.getElementById("id& ...

  2. getElementByName()和getElementById的区别

    因为在属性中,id时唯一的,getElementById取出的是一个元素但是可以出现相同的name,取到的是一个Array ,getElementsByName取出的是数组 记录代码如下: <! ...

  3. js DOM Document类型

    JavaScript通过Document类型访问文档.在浏览器中,document对象是HTMLDocument(继承自 Document类型)的一个实例,表示整个HTML页面.document对象是 ...

  4. 关于document.getElement获取元素返回值的问题

    获取网页元素有很多种方法,如下: document.all[];返回HTMLElement对象 document.all.tags[];返回NodeList对象,类似数组 document.getEl ...

  5. Javascript之document对象用法(很重要)

    一.找到元素 document.getElementById("id"):根据id找层,最多找一个 var a=document.getElementById("id&q ...

  6. JavaScript之document对象使用

    1.document 对象常用的有三种: A.document.getElementById:通过html元素的Id,来获取html对象.适用于单个的html元素. B.document.getEle ...

  7. JavsScript中的Document对象

    Document对象的属性 alinkColor,linkColor,vlinkColor:这些属性描述了超链接的颜色.linkColor指未访问过的链接的正常颜色,vlinkColor指访问过的链接 ...

  8. 从原型链看DOM--Document类型

    JavaScript通过Document类型表示文档,原型链的继承关系为:document.__proto__->HTMLDocument.prototype->Document.prot ...

  9. 批量处理标签属性中document.getElementsByName()的替代方案

    背景 今天在逛知乎时候,看到一个JavaScript方面的问题: 最近在学习JavaScript DOM,就好奇地查阅资料,以及请教学长,得到下面解答: http://www.w3help.org/z ...

随机推荐

  1. 你不知道的javascript 上卷 读书笔记

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  2. C#垃圾回收机制详解

    一.托管代码/非托管代码 C#代码通过C#编译器编译成程序集,程序集由微软中间语言组成,CLR会为程序集开辟一个应用程序域,程序集就是运行在这个应用程序域里面的,应用程序域是相互独立的,互不影响. 托 ...

  3. Java分布式缓存框架

    http://developer.51cto.com/art/201411/457423.htm 在开发中大型Java软件项目时,很多Java架构师都会遇到数据库读写瓶颈,如果你在系统架构时并没有将缓 ...

  4. c标准库中字符和数字转换的函数

    字符转换为数字: #include<stdlib.h> atoi();    将字符转换为整型                       例:char ch1;int i=atoi(ch ...

  5. Windows 7中,用Visual Studio开发WPF应用程序,实现从Windows Explorer中拖拽文件到应用程序,始终显示“无法拖放”符号问题解决方案

    Are you running your application or Visual Studio that hosts the app under administrative privilege? ...

  6. powerbulider9.0在数据窗口中实现滚动到新添加行

    powerbuilder9.0对数据窗口进行增加行操作,然后实现滚动到指定行时,应先滚动到指定行dw_1.scrolltorow( row),然后设置新添加的行为当前行dw_1.setrow( row ...

  7. js 实现图片旋转角度

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  8. Matlab网格划分

    之前转载了一篇博客http://blog.sina.com.cn/s/blog_6163bdeb0102dvay.html,讲Matlab网格划分程序Distmesh,看了看程序,感觉程序写得有很多值 ...

  9. 解决Mysql的主从数据库没有同步的两种方法

    今天发现Mysql的主从数据库没有同步 先上Master库: mysql>show processlist;   查看下进程是否Sleep太多.发现很正常.show master status; ...

  10. JavaScript之Chart.js图例(legend)

    #html <div id="chart_line_legend" class="chart-legend"></div> <ca ...