元素的ID慎用length

简介:

 先来看看一段错误的代码:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>无标题文档</title> <mce:script type="text/javascript"><!-- (function(){ //id=length var d=document.getElementsByTagName("input").length; alert(d); })(); // --></mce:script> </head> <body> <form id="form"> <input type="text" id="length" /> <input type="submit" id="submit" /> </form> </body> </html> 

 

这段代码中第一个input的ID为length,我们可以在Ie,firefox的结果都是0,这些都是<input type="text" id="length"/>惹的祸,因此我们可要注意了

目录
相关文章
element-ui table排序sortable三种状态,怎么去掉默认状态
在 element-ui 中,也定义了 sort-orders 有三种状态: ascending、descending、null,这三种状态形成一个循环切换。
2181 0
|
3月前
|
前端开发 程序员
【面试题】在循环 for、for-in、forEach、for-of 、map中改变item的值,会发生什么?
【面试题】在循环 for、for-in、forEach、for-of 、map中改变item的值,会发生什么?
|
10天前
287--寻找重复数-indexOf-&&-sort
287--寻找重复数-indexOf-&&-sort
11 1
|
2月前
|
JSON 算法 前端开发
2722. 根据 ID 合并两个数组
2722. 根据 ID 合并两个数组
15 0
|
6月前
|
Python
python之列表中常用的函数:append,extend,insert,pop,remove,del函数的定义与使用方法,元素是否在列表中的判断
python之列表中常用的函数:append,extend,insert,pop,remove,del函数的定义与使用方法,元素是否在列表中的判断
|
8月前
对List进行排序,值为null的排到最后
对List进行排序,值为null的排到最后
|
3月前
|
JavaScript 前端开发 开发者
div 元素的 tab-index 属性被设置为 -1,意味着什么
div 元素的 tab-index 属性被设置为 -1,意味着什么
24 0
|
10月前
|
JavaScript 索引
vue 数组处理= 循环--查找过滤--添加删除--去重[.every()/.some()/.find()/.filter()/.forEach()/.map()]
vue 数组处理= 循环--查找过滤--添加删除--去重[.every()/.some()/.find()/.filter()/.forEach()/.map()]
190 0
vue 数组处理= 循环--查找过滤--添加删除--去重[.every()/.some()/.find()/.filter()/.forEach()/.map()]
map使用const char*作为key值查找注意事项
map使用const char*作为key值查找注意事项
|
算法 安全 Java
Array,List,Set及Map遍历内容的方法探究
Array,List,Set及Map遍历内容的方法探究