jquery中选择器input:hidden和input[type=hidden]的区别
关于选择器:hidden的说明,在jquery说明文档中是这样说的:匹配所有不可见元素,或者type为hidden的元素。而[type=hidden]是查找所有type属性等于hidden的元素。两者是有相同之处和不同之处的。:hidden匹配所有不可见元素,或者type为hidden的元素,所有样式display等于none的元素和子元素以及type="hidden"的表单元素都在查找的结果中,而[type=hidden]则只查找type属性为hidden的元素。
所以,input:hidden是查找不可见容器中的input元素,包括,textbox,radio,checkbox,button等和type="hidden"的表单元素。input[type=hidden]仅仅查找type="hidden"的表单元素。如以下例子:

<!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>jquery Demo</title>
<script type="text/javascript" src="jquery-1.7.1.min.js"></script>
<script type="text/javascript">
function beforeHidden()
{
$("#result").text("隐藏前:$(\"input:hidden\").length="+$("input:hidden").length+";$(\"input[type=hidden]\").length="+$("input[type=hidden]").length);
}
function afterHidden()
{
$("#div1").hide();
$("#result").append("<br/>隐藏后:$(\"input:hidden\").length="+$("input:hidden").length+";$(\"input[type=hidden]\").length="+$("input[type=hidden]").length);
}
</script>
</head> <body>
<form id="form1" name="form1" method="post" action="">
<div id="div1">
<input type="text" id="txt" />
<input type="radio" id="rdo" /><label for="rdo">单选框</label>
<input type="checkbox" id="chx"/><label for="chx">复选框</label>
<br />
<input type="button" id="btn1" value="原始" onclick="beforeHidden();"/>
</div>
<input type="hidden" id="hd"/>
<input type="button" id="btn2" value="隐藏后" onclick="afterHidden();"/>
<div id="result"></div></form>
</body>
</html>

例子中,div1被隐藏前,$("input:hidden").length=1;$("input[type=hidden]").length=1,隐藏后,隐藏后:$("input:hidden").length=5;$("input[type=hidden]").length=1,显然,div1中的<input type="text" id="txt" />
<input type="radio" id="rdo" />
<input type="checkbox" id="chx"/>
<input type="button" id="btn1" value="原始"/>也被包含进来了,而$("input[type=hidden]").length始终没有变。
jquery中选择器input:hidden和input[type=hidden]的区别的更多相关文章
- jquery中选择器的 html() text() val() attr() 方法的区别与使用方式
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- jquery中innerwidth,outerwidth,outerwidth和width的区别
在jQuery中,width()方法用于获得元素宽度: innerWidth()方法用于获得包括内边界(padding)的元素宽度, outerWidth()方法用于获得包括内边界(padding)和 ...
- jquery中ready函数,$(function(){})与自执行函数的区别
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...
- 详解jQuery中 .bind() vs .live() vs .delegate() vs .on() 的区别
转载自:http://zhuzhichao.com/2013/12/differences-between-jquery-bind-vs-live/ 我见过很多开发者很困惑关于jQuery中的.bin ...
- 在JQuery中$(document.body)和这个$("body") 这两的区别在哪里?
两种写法代表的是同一个对象 $("body") 是一个选择器,jQuery 会从 DOM 顶端开始搜索,直到找到标签为 body 的元素. 而 $(document.body) 中 ...
- jQuery中append()、prepend()与after()、before()的区别
转载 未曾见海 https://www.cnblogs.com/afei-qwerty/p/6682963.html 在jQuery中,添加元素有append(),prepend() 和 after ...
- jquery中append、prepend, before和after方法的区别(一)
原文:http://blog.csdn.net/woosido123/article/details/64439490 在 jquery中append() 与 prepend()是在元素内插入内容(该 ...
- JQuery中阻止事件冒泡的两种方式及其区别
JQuery 提供了两种方式来阻止事件冒泡. 方式一:event.stopPropagation(); $("#div1").mousedown(function(event){ ...
- jQuery中操作属性的方法attr与prop的区别
attr 与 prop 都可以对某个属性进行获取和设置的操作,二者的用法相同: <script src = 'jQuery.js'></script> <script&g ...
随机推荐
- instance of的java用法
http://blog.csdn.net/liranke/article/details/5574791
- jquery开发插件提供的几种方法
http://caibaojian.com/jquery-extend-and-jquery-fn-extend.html
- sql取逗号前后数据与批量修改某一字段某一值
sql取逗号后的值 SELECT SUBSTRING_INDEX(字段,) FROM 表名 sql取逗号前的值 SELECT SUBSTRING_INDEX(字段,) FROM 表名 批量修改 UPD ...
- [ 高危 ] mt网主站SQL注入
rank 75 金币 75 等价RMB 750 数据包样式如下 POST /ajax.php HOST: xxx.meituan.com Cookie: xxx id=123&job= ...
- Django 学习第六天——Django模型基础第一节
一.Django 的 ORM 简介: Django的ORM系统的分析: 1.ORM 概念:对象关系映射(Object Relational Mapping,简称ORM) 2.ORM的优势:不用直接编写 ...
- 记录初学者学习Hive时踩过的坑
1. 缺少MySQL驱动包 1.1 问题描述 Caused by: org.datanucleus.store.rdbms.connectionpool.DatastoreDriverNotFound ...
- Java 实现String语句的执行(Jexl)
https://www.jianshu.com/p/1000719e49fa 1.maven 导入库 <dependency> <groupId>org.apache.comm ...
- 无可奈何的开始了jquery的“奇淫技巧”
转载请注明出处: https://home.cnblogs.com/u/zhiyong-ITNote/ 修改一个已有的项目,主要是前端方面,一般的项目后端都是处理好了的,不需要改也不能改,除非特殊需求 ...
- 解决nuxt.js新建项目报错的问题
查了一下nuxt的github才知道是node.js版本太低造成的,据说升级到8.6以上就可以了(本人直接升了9.9) node_modules\nuxt\lib\core\middleware\nu ...
- [USACO18JAN]Cow at Large P
Description: 贝茜被农民们逼进了一个偏僻的农场.农场可视为一棵有 \(N\) 个结点的树,结点分别编号为 \(1,2,\ldots, N\) .每个叶子结点都是出入口.开始时,每个出入口都 ...