惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

P
Privacy International News Feed
MongoDB | Blog
MongoDB | Blog
WordPress大学
WordPress大学
小众软件
小众软件
H
Hacker News: Front Page
S
Securelist
S
SegmentFault 最新的问题
Jina AI
Jina AI
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
阮一峰的网络日志
阮一峰的网络日志
G
GRAHAM CLULEY
P
Palo Alto Networks Blog
博客园 - 司徒正美
量子位
罗磊的独立博客
大猫的无限游戏
大猫的无限游戏
Cyberwarzone
Cyberwarzone
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
P
Privacy & Cybersecurity Law Blog
月光博客
月光博客
V
Visual Studio Blog
C
CERT Recently Published Vulnerability Notes
爱范儿
爱范儿
T
Threat Research - Cisco Blogs
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Apple Machine Learning Research
Apple Machine Learning Research
T
The Exploit Database - CXSecurity.com
T
Tenable Blog
L
LINUX DO - 热门话题
MyScale Blog
MyScale Blog
Hugging Face - Blog
Hugging Face - Blog
M
MIT News - Artificial intelligence
腾讯CDC
NISL@THU
NISL@THU
A
Arctic Wolf
Scott Helme
Scott Helme
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
宝玉的分享
宝玉的分享
T
Tailwind CSS Blog
L
LINUX DO - 最新话题
The GitHub Blog
The GitHub Blog
Help Net Security
Help Net Security
C
Check Point Blog
O
OpenAI News
D
DataBreaches.Net
I
InfoQ
N
News and Events Feed by Topic
S
Security @ Cisco Blogs
D
Darknet – Hacking Tools, Hacker News & Cyber Security
F
Fortinet All Blogs

博客园 - MangaGo

在网页里让文本框只能输入数字的一种方法。外加回车换Tab - MangaGo - 博客园 (转) WINDOWS下的使用VS.NET2005的SVN手记 学习.Net的经典网站 Subversion快速入门教程 ASP.NET 2.0 下配置 FCKeditor - MangaGo asp中验证码图片为BMP格式,但是不显示 [Serializable]在C#中的作用-NET 中的对象序列化 VSS服务器安装配置 TimeSpan 用法 求离最近发表时间的函数 - MangaGo javascript判断密码安全级别 js获得当前日期并 显示 - MangaGo - 博客园 永远不要跟父母说的十句话,谁没说过? 在ASP.NET里轻松实现缩略图 用ASP.NET缓存提高站点性能【转载】 一个sql中常遇到的表结构转换问题 一个冒泡排序算法 一列数的规则如下: 1、1、2、3、5、8、13、21、34...... 求第30位数是多少, 用递归算法实现 阶乘的经典算法! 关于上传文件的大小限制
document.getElementById 你真正了解了吗 - MangaGo - 博客园
MangaGo · 2008-01-10 · via 博客园 - MangaGo

text1:
    <input name="textName1" type="text" id="textName2" />
<br>
  text2:
    <input name="textName2" type="text" id="textName1" />
<br>
  <input type="button" name="Submit" value="text1"  onclick=alert(document.getElementById('textName2').value) />
  <input type="button" name="Submit2" value="text2"  onclick=alert(document.getElementById('textName1').value) />

我在IE中测试了上面的代码,在第一个文本框中输入1,在第二个文本框中输入2,然后点下面的两个按钮,猜一下结果是什么?

我本意是按钮1返回第一个文本框的值,按钮2返回个文本框的值。

结果是两个按钮都返回了第一个文本框的值。

说明ie执行document.getElementById(elementName)的时候,返回的是第一个name或者id等于elementName的对象,并不是按照ID来查找的。

在fireFox中不存在这样的问题,fireFox执行document.getElementById(elementName)的时候只查找id等于elementName的对象,如果不存在则返回null。

可能IE是考虑的兼容性的问题才这么做的。