前面的话

  无论是提交还是传递数据,表单元素在动态交互页面的作用是非常重要的。jQuery专门加入了表单选择器,从而能够极其方便地获取到某个类型的表单元素

表单元素选择器

:input

  :input选择器选择input、textarea、select和button元素  

:text

 :text选择器选择所有的单行文本框 

:password

  :password选择器选择所有的密码框

:radio

  :radio选择器选择所有的单选框

:checkbox

  :checkbox选择器选择所有的多选框

:submit

  :submit选择器选择所有的提交按钮

:image

  :image选择器选择所有的图像按钮

:reset

  :reset选择器选择所有的重置按钮

:button

  :button选择器选择所有的按钮

:file

  :file选择器选择所有的文件上传域

  [注意]大部分表单类别筛选器可以使用属性筛选器替换

  ':password'可以写为'[type=password]'

<button id="btn1" style="color: red;">$(':input')</button>
<button id="btn2" style="color: #A2CD5A;">$(':text')</button>
<button id="btn3" style="color: yellow;">$(':password')</button>
<button id="btn4">$(':radio')</button>
<button id="btn5">$(':checkbox')</button>
<button id="btn6" style="color: #C6E2FF">$(':submit')</button>
<button id="btn7" style="color: #F4A460;">$(':image')</button>
<button id="btn8" style="color: green;">$(':button')</button>
<button id="btn9" style="color: #CD1076;">$(':file')</button>
<button id="btn10" style="color: pink;">$(':reset')</button>
<button id="reset">还原</button>
<form id="box">
<input type="text" value="text类型"/>
<input type="password" value="password"/>
<input type="radio"/>
<input type="checkbox"/>
<input type="submit" />
<input type="image" />
<input type="button" value="Button" />
<input type="file" />
<input type="reset" />
</form>
<script>
reset.onclick = function(){history.go();}
btn1.onclick = function(){$('#box :input').css("border", "1px groove red");}
btn2.onclick = function(){ $(':text').css("background", "#A2CD5A");}
btn3.onclick = function(){$(':password').css("background", "yellow");}
btn4.onclick = function(){$(':radio').attr('checked','true');}
btn5.onclick = function(){$(':checkbox').attr('checked','true');}
btn6.onclick = function(){$('#box :submit').css("background", "#C6E2FF"); }
btn7.onclick = function(){$(':image').css("background", "#F4A460"); }
btn8.onclick = function(){ $('#box :button').css("background", "green"); }
btn9.onclick = function(){$(':file').css("background", "#CD1076"); }
btn10.onclick = function(){$(':reset').css("background", "pink"); }
</script>

表单对象属性选择器

:enabled

  :enabled选择器选择可用的表单元素

:disabled

  :disabled选择器选择不可用的表单元素

<button id="btn1" style="color: red;">$(':enabled')</button>
<button id="btn2" style="color: #A2CD5A;">$(':disabled')</button>
<button id="reset">还原</button>
<form>
<input type="text" />
<input type="text" disabled/>
<input type="text" />
</form>
<script src="jquery-3.1.0.js"></script>
<script>
reset.onclick = function(){history.go();}
btn1.onclick = function(){$('form :enabled').css("background", "red");}
btn2.onclick = function(){ $(':disabled').css("background", "#A2CD5A");}
</script>

:checked

  :checked选择器选择被选中的<input>元素(单选框、复选框)

<button id="btn1">$(':checked')</button>
<button id="reset">还原</button>
<form>
<input type="checkbox" checked>
<input type="checkbox">
<input type="radio" checked>
<input type="radio">
</form>
<script>
reset.onclick = function(){history.go();}
btn1.onclick = function(){$(':checked').removeAttr('checked')}
</script>

:selected

  :selected选择器选择被选中的<option>元素(下拉列表)

<button id="btn1">$(':selected')</button>
<button id="reset">还原</button>
<select multiple>
<option>1</option>
<option selected>2</option>
<option>3</option>
<option selected>4</option>
</select>
<script>
reset.onclick = function(){history.go();}
btn1.onclick = function(){$(':selected').removeAttr('selected')}
</script>

深入学习jQuery选择器系列第七篇——表单选择器的更多相关文章

  1. Vue.js学习笔记 第七篇 表单控件绑定

    本篇主要说明表单控件的数据绑定,这次没有新的知识点 文本框 1.普通文本框 <div id="app-1"> <p><input v-model=&q ...

  2. 深入理解ajax系列第八篇——表单提交

    前面的话 在以前,网站的用户与后端交互的主要方式是通过HTML表单的使用.表单的引入在1993年,由于其简单性和易用性,直到电子商务出现之前一直保持着重要位置.理解表单提交,对于更深入地理解ajax是 ...

  3. jQuery事件篇---过滤选择器 & 表单选择器

    内容提纲: 过滤选择器 1.基本过滤器 2.内容过滤器 3.可见性过滤器 4.子元素过滤器 5.其他方法 表单选择器 6.常规选择器 7.表单选择器 8.表单过滤器 发文不易,转载请注明出处! 过滤选 ...

  4. jQuery学习笔记(一)——基础选择器、过滤选择器、表单选择器

    $()就是jQuery中的函数,它的功能是获得()中指定的标签元素.如演示样例中$("p")会得到一组P标签元素,当中"p"表示CSS中的标签选择器.$()中的 ...

  5. 第一百六十八节,jQuery,表单选择器

    jQuery,表单选择器 学习要点: 1.常规选择器 2.表单选择器 3.表单过滤器 表单作为 HTML 中一种特殊的元素,操作方法较为多样性和特殊性,开发者不但可以 使用之前的常规选择器或过滤器,也 ...

  6. jQuery选择器介绍:基本选择器、层次选择器、过滤选择器、表单选择器

    选择器是jQuery的根基,在jQuery中,对事件处理.遍历DOM和Ajax操作都依赖于选择器.因此,如果能熟练的使用选择器,不仅能简化代码,而且可以达到事半功倍的效果.jQuery选择器完全继承了 ...

  7. jQuery编程基础精华02(属性、表单过滤器,元素的each,表单选择器,子元素过滤器(*),追加方法,节点,样式操作)

    属性.表单过滤器 属性过滤选择器: $("div[id]")选取有id属性的<div> $("div[title=test]")选取title属性为 ...

  8. JQuery -- 介绍,选择器及其示例, 基本选择器,层次选择器,过滤选择器,表单选择器

    1. 什么是jQuery对象 jQuery 对象就是通过jQuery包装DOM对象后产生的对象. jQuery对象是jQuery独有的.如果一个对象是jQuery对象,那么它就可以使用jQuery里的 ...

  9. jquery表单选择器

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

随机推荐

  1. Python 键盘记录

    之前写的键盘记录最后一直在纠结弹框与不弹框的问题,代码找不到了,今天重新来一遍 #!/usr/bin/env python# -*-coding:utf-8 -*-from ctypes import ...

  2. mac新手的烦恼

    最近新换了mac,我换mac并非自愿.无论mac的性能有多好,我依然讨厌使用appstore下载软件的感觉,尤其在我一遍又一遍忘记自己的appID的时候.无奈我的thinkpad常常死机,最近又常倒腾 ...

  3. android copy项目后修改项目名

    有个eclipse下的Android项目,现在因为有个需求想在复制出来一个项目,把这个项目变成两个独立项目.在同一个工作空间下不能同时存在项目名称一样的项目,所以需要修改项目名.具体操作如下: 1.修 ...

  4. Redis集群最佳实践

    今天我们来聊一聊Redis集群.先看看集群的特点,我对它的理解是要需要同时满足高可用性以及可扩展性,即任何时候对外的接口都要是基本可用的并具备一定的灾备能力,同时节点的数量能够根据业务量级的大小动态的 ...

  5. Where product development should start

    We all need to know our customers in order to create products they’ll actually buy. This is why the  ...

  6. Redis 做消息队列

    一般来说,消息队列有两种场景,一种是发布者订阅者模式,一种是生产者消费者模式.利用redis这两种场景的消息队列都能够实现.定义: 生产者消费者模式:生产者生产消息放到队列里,多个消费者同时监听队列, ...

  7. angularjs 解决ng-repeat数组内重复对象报错的问题

    ng-repeat 循环数组内元素时,如果数组内元素重复,angular会抛出异常: Error: [ngRepeat:dupes] http://errors.angularjs.org/1.4.3 ...

  8. PHP 通过百度API 实现通过城市名称获取经度

    $city = $_GET['city'];print_r(getjw($city));/*** $city 需要查询的地址* $key 百度开发者账号*/function getjw($city){ ...

  9. java面向对象_static关键字

    1. 修饰成员变量:有static修饰的为静态变量,没有static修饰的称为实例变量. 实例变量:属于对象的,一个对象有一份.在创建对象的时候被初始化,存在多个副本,各个对象拥有的副本互不影响.存储 ...

  10. CYQ.Data 批量添加数据性能测试(每秒千、万)

    今天有网友火晋地同学进了CYQ.Data官方群了,他正在折腾了一个各大ORM性能测试的比较的软件,如下图 折腾的种类也不少: 感觉这软件折腾的不错~~~值的期待~~~ 另外,他指出CYQ.Data 在 ...