没有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 ...
随机推荐
- 移动端布局Demo展示图文
上两张图自勉一下(来自刘墉先生的文章,最近看他的作品):然后移动端该愈来愈受到重视,未来的市场我不知道,不过我知道手机的功能越来越强大是不争的事实!移动端布局的积累也需要从现在做起! 需求一:实现下图 ...
- 万网免费主机wordpress快速建站教程-wordpress下载及安装
进入wordpress官网(http://cn.wordpress.org)下载最新的wordpress安装程序,下载完成后解压到任意电脑目录. 解压完毕后,使用FTP管理工具上传安装文件至主机htd ...
- Discuz!nt整合心得
最近研究了下Discuz!nt的整合,因为是网上找的实例,有个地方的写错了,导致纠结了一整天,这里分享出来. Discuz!nt提供了整合工具DiscuzToolkit,用于调用Discuz!nt A ...
- 一步一步学NUnit
转载:http://tech.sina.com.cn/s/2009-07-17/1129988785.shtml 单元测试基础知识 单元测试是开发者编写的一小段代码,用于检验被测代码的一个很小的.很明 ...
- iOS9 http不能访问网络——在Xcode中将https改成http方式
=====================2016-01-29更新=========================== 最近做demo时,发现将https改成http方式略有小变 1. 没有改成ht ...
- asp:时间的计算
DataTime dt = new DataTime();//dt为时间DataTime对象 dt.ToString();//2005-11-5 13:47:04 dt.AddYears(1).ToS ...
- redis基本数据类型【2】-Hash类型
一.概述 1.散列是一种典型的字典结构,filed和value的映射,但value只能存储字符串,不支持其他类型 2.一个散列类型最多包含 2^32 -1个字段 3.散列适合存储对象:使用对象和ID构 ...
- POJ 2711 Regular Words(DP + 高精度)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1711 题目大意:给定一个正整数n,产生一个3*n位长的串,要求这个串 ...
- Android中为窗口定义主题
在res/values/styles文件夹中定义如下: <style name="myTheme"> <item name="android:windo ...
- Hdu 1452 Happy 2004(除数和函数,快速幂乘(模),乘法逆元)
Problem Description Considera positive integer X,and let S be the sum of all positive integer diviso ...