首先声明的是:

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. webstom 如何获取github上面的项目工程

    需要你配好webstorm的github相关的配置,安装好git.exe; 如何配置请参考: webstorm 如何配置git 这个点击github后 会有个提示框 如下图: 如果没有成功,会弹出下面 ...

  2. Git之路--2

  3. MVC中HtmlHelper用法大全参考

    MVC中HtmlHelper用法大全参考 解析MVC中HtmlHelper控件7个大类中各个控件的主要使用方法(1) 2012-02-27 16:25 HtmlHelper类在命令System.Web ...

  4. Oracle SQL 基础学习

    oracel sql 基础学习 CREATE TABLE USERINFO ( ID ,) PRIMARY KEY, USERNAME ), USERPWD ), EMAIL ), REDATE DA ...

  5. iOS 9 Spotlight搜索 OC版

    介绍:    在WWDC 2015会议上,苹果官方公布了iOS9.除开许多新的特性和增强功能,这次升级也给了开发者们一个机会让他们的app里的内容能通过Spotlight 搜索功能被发现和使用.在iO ...

  6. NSArray 常用的一些方法

    - (NSUInteger) count; 返回数组中元素个数 - (id)objectAtIndex:(NSUInteger)index; 返回一个id类型的数组指定位置元素 - (id)lastO ...

  7. 使windows server 2003 开机不显示登录页面

    1.运行“regedit”,以打开“注册表管理器”:运行注册表编辑器,依次展开[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\WindowsNT\CurrentVersi ...

  8. jQuery的基础语法实例

    jQuery 基础语法 jQuery 语法是为 HTML 元素的选取编制的,可以对元素执行某些操作. 基础语法是:$(selector).action() 美元符号定义 jQuery 选择符(sele ...

  9. 02_天气查询_socket方式模拟_单线程

    [远程请求的B/S模式(客户端/服务器)] TCP: 是一种传输层协议,一种面向连接的协议.经过三次握手客户端和服务器端连接一个连接(通道).提供可靠的数据传输,该协议一般服务质量要求比较高的情况,T ...

  10. js判断是否全是相同的字符串

    isSameStr("aa2a") //不都是相同的字符 function isSameStr(str){ var tem=0; for(var i=0;i<str.leng ...