document.getElementsByName和document.getElementById用法
本文的问题在国外的一个网站得到了答案http://stackoverflow.com/questions/11235409/no-getelementbyid-for-body
document.body.getElementsByTagName()
document.body.getElementsByClassName()
document.getElementById
document.getElementsByName
解释如下:
你可以有多个元素相同的类名所以缩小搜索开始与一个特定的节点有意义。
它没有意义,因为它与id应该是唯一的。
你只能有一个id在文档,这为什么是一个方法的文档getElementById。
文档还有一个方法就是getElementsByName 返回的是returns an HTMLCollection
但是document.body.getElementsByName为什么没有呢?
是因为:
当你使用document.getElementsByName方法得到指定名称下,文档中的所有元素的NAME属性指定或ID属性值返回。
元素,同时支持名称属性和ID属性包含在返回的集合getElementsByName方法得到指定名称下的,但元素名称expando并不包含在集合;因此,这种方法不能用于检索自定义标记的名字。
这就不难理解了。
document.getElementsByName和document.getElementById用法的更多相关文章
- IE9 使用document.getElementsByName("abc") 不能获取到名称相同SPAN元素
<div name="abc"></div> <input name="abc" type="text" /& ...
- ie8以下不兼容document.getElementsByName解决方法
在IE8以认为只有文本标签才有name属性的,一些元素标签用document.getElementsByName获取不到DOM,如DIV,span等,这里做一下兼容. HTML: <div na ...
- ie用document.getElementsByName获取不到
document.getElementsByName('someName') 返回一个节点列表(数组) 注意:在IE下有些节点是没有name 属性的,就是用document.getElementsBy ...
- 批量处理标签属性中document.getElementsByName()的替代方案
背景 今天在逛知乎时候,看到一个JavaScript方面的问题: 最近在学习JavaScript DOM,就好奇地查阅资料,以及请教学长,得到下面解答: http://www.w3help.org/z ...
- HTML5中类jQuery选择器querySelector的高级使用 document.querySelectorAll.bind(document);
基本用法 querySelector 该方法返回满足条件的单个元素.按照深度优先和先序遍历的原则使用参数提供的CSS选择器在DOM进行查找,返回第一个满足条件的元素. ----> querySe ...
- 各浏览器对使用 document.id 和 document.name 获取对象的支持存在差异
标准参考 无. 问题描述 各浏览器使用 document.id 和 document.name 方法获取对象引用的支持存在差异. 造成的影响 某些浏览器中通过 document.id 和 docume ...
- 【转】document.documentElement和document.body的区别
转自:http://www.cnblogs.com/ckmouse/archive/2012/01/30/2332070.html 网页中获取滚动条卷去部分的高度,可以通过 document.body ...
- document.documentElement和document.body的区别
网页中获取滚动条卷去部分的高度,可以通过 document.body.scrollTop 来获取,比如使div跟着滚动条滚动: <div id="div" style=&qu ...
- document.body、document.documentElement和window获取视窗大小的区别
来源:http://www.ido321.com/906.html 在w3school关于window对象的介绍中,介绍了获取浏览器窗口大小的三种方法(浏览器的视口,不包括工具栏和滚动条). 对于In ...
随机推荐
- Nearest Neighbor Search
## Nearest Neighbor Search ## Input file: standard input Output file: standard output Time limit: 1 ...
- 苹果无sim卡激活
韩梦飞沙 韩亚飞 313134555@qq.com yue31313 han_meng_fei_sha 苹果无sim卡激活 这是不行的... 必须有SIM 卡. 有可能卡贴坏了,更换卡贴.
- hdu 1011 树形dp+背包
题意:有n个房间结构可看成一棵树,有m个士兵,从1号房间开始让士兵向相邻的房间出发,每个房间有一定的敌人,每个士兵可以对抗20个敌人,士兵在某个房间对抗敌人使无法走开,同时有一个价值,问你花费这m个士 ...
- bzoj 1269 bzoj 1507 Splay处理文本信息
bzoj 1269 题目:http://www.lydsy.com/JudgeOnline/problem.php?id=1269 大致思路: 用splay维护整个文本信息,splay树的中序遍历即为 ...
- hdu 5204 Rikka with sequence 智商不够系列
Rikka with sequence Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.p ...
- Codeforces Round #303 (Div. 2) C. Woodcutters 贪心
C. Woodcutters Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/545/probl ...
- mysqldump导出CSV格式及where导出时间范围问题解决
众所周知,mysqldump不但可以导出sql格式,还可以导出csv格式. 导出CSV格式的具体使用如下命令. mysqldump -uroot -ppassword -S /tmp/mysql999 ...
- 如何解决…has been modified since the precompiled header… was built的问题
如何解决…has been modified since the precompiled header… was built 的问题 xcode5.1在程序中报错: File '/Applicatio ...
- 升压转换器 (Boost)
升压转换器 (Boost) 需要将输入电压转换为较高的输出电压时,升压转换器 (Boost)是唯一的选择. 升压转换器透过内部 MOSFET 对电压充电来达成升压输出的目的,而当 MOSFET 关闭时 ...
- Inrush limiter also provides short-circuit protection
For containing large amounts of bulk capacitance, controlling inrush currents poses problems. The si ...