没有document.getElementByName
首先声明的是:
|
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
作用:一般页面里ID是唯一的,用于准备定位一个元素
语法: document.getElementById(id)
参数:id :必选项为字符串(String)
返回值:对象; 返回相同id对象中的第一个,按在页面中出现的次序,如果无符合条件的对象,则返回 null
example:
document.getElementById("id1").value;
2、getElementsByName
作用:按元素的名称查找,返回一个同名元素的数组
语法: document.getElementsByName(name)
参数:name :必选项为字符串(String)
返回值:数组对象; 如果无符合条件的对象,则返回空数组,按在页面中出现的次序
example:
document.getElementsByName("name1")[0].value;
document.getElementsByName("name1")[1].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的更多相关文章
- Windows.document
一.找到元素: document.getElementById("id");根据id找,最多找一个 var a =document.getElementById("id& ...
- getElementByName()和getElementById的区别
因为在属性中,id时唯一的,getElementById取出的是一个元素但是可以出现相同的name,取到的是一个Array ,getElementsByName取出的是数组 记录代码如下: <! ...
- js DOM Document类型
JavaScript通过Document类型访问文档.在浏览器中,document对象是HTMLDocument(继承自 Document类型)的一个实例,表示整个HTML页面.document对象是 ...
- 关于document.getElement获取元素返回值的问题
获取网页元素有很多种方法,如下: document.all[];返回HTMLElement对象 document.all.tags[];返回NodeList对象,类似数组 document.getEl ...
- Javascript之document对象用法(很重要)
一.找到元素 document.getElementById("id"):根据id找层,最多找一个 var a=document.getElementById("id&q ...
- JavaScript之document对象使用
1.document 对象常用的有三种: A.document.getElementById:通过html元素的Id,来获取html对象.适用于单个的html元素. B.document.getEle ...
- JavsScript中的Document对象
Document对象的属性 alinkColor,linkColor,vlinkColor:这些属性描述了超链接的颜色.linkColor指未访问过的链接的正常颜色,vlinkColor指访问过的链接 ...
- 从原型链看DOM--Document类型
JavaScript通过Document类型表示文档,原型链的继承关系为:document.__proto__->HTMLDocument.prototype->Document.prot ...
- 批量处理标签属性中document.getElementsByName()的替代方案
背景 今天在逛知乎时候,看到一个JavaScript方面的问题: 最近在学习JavaScript DOM,就好奇地查阅资料,以及请教学长,得到下面解答: http://www.w3help.org/z ...
随机推荐
- hibernate篇章二--成就搭建hibernate框架
在网上的资料很多,但是成功搭建一个Hibernate框架的很少,下面我将用一个简单的例子成功搭建一个Hibernate框架给大伙瞧瞧 该链接中有源代码和数据库,例子很简单,只是往数据库中的person ...
- virtualbox安装ubuntu出现“The system is running in low-graphics mode”
cd /etc/X11 sudo mv xorg.conf.failsafe xorg.conf sudo reboot 即可.
- (五)Hibernate 操作对象
所有项目导入对应的hibernate的jar包.mysql的jar包和添加每次都需要用到的HibernateUtil.java 第一节:Hibernate 中四种对象状态 临时状态(transient ...
- 10.10_魔兽账号,OSC代码托管演示,研究SQL别忘记了,git
(1)juedui8456juedui456chixin0769魔兽世界账号112288 (2)EasyXls.开源中国推出 PaaS@OSC 代码演示和运行平台.git.oschina.coding ...
- VIM 及正则表达式
VIM及正则表达式 一.查找/Search + 统计 1.统计某个关键字 方法是:%s:keyword:&:gn. 其中,keyword是要搜索的关键字,&表示前面匹配的字符串,n表示 ...
- itoa : Convert integer to string
Quote from: http://www.cplusplus.com/reference/cstdlib/itoa/ function Required header : <s ...
- SSL Programming Tutorial
SSL Programming Tutorial � Table of Contents [ � Index This section demonstrates the implement ...
- [記錄用]python py2app 檔案批次重新命名
demo.py 主要作用為 將同目錄下 *.mp4 檔案批次重新命名 例如: aaa001.mp4 ---重新命名為--> 001.mp4 aaa002.mp4 ---重新命名為--> 0 ...
- 多目标遗传算法 ------ NSGA-II (部分源码解析)状态报告 打印 report.c
/* Routines for storing population data into files */ # include <stdio.h> # include <stdlib ...
- Java集合类操作优化总结
清单 1.集合类之间关系 Collection├List│├LinkedList│├ArrayList│└Vector│ └Stack└SetMap├Hashtable├HashMap└WeakHas ...