前面的话

  无论是提交还是传递数据,表单元素在动态交互页面的作用是非常重要的。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. db2基础

    DB2知识文档 一.db2 基础 基本语法 注释:"--"(两个减号) 字符串连接:"||" 如set msg='aaaa'||'bbbb',则msg为'aaa ...

  2. 案例1.通过Jquery来处理复选框

    实现以下功能: 1:选中第一个复选框,那么下面所有的复选框都选中,去除选中第一个复选框,下面的都不选中 2:当点击全选按钮,上面足球.篮球.游泳.唱歌 全部选中 3:当点击全不选按钮,上面四个全部取消 ...

  3. Object-C与Swift混编

    1.在Object-C项目中调用Swift 1.1.创建一个Object-C project(项目名例如:YYDemo) 如下图 1.2.创建一个Swift Class,如下图 这里会显示是否需要创建 ...

  4. elasticsearch一些常用的配置

    配置了解 cluster #配置下集群的名称 cluster.name: my-application

  5. [ios]利用alertView 插入数据都数据库。笔记

    利用alertView 插入数据都数据库 -(void)addItemToList { UIAlertView *alter=[[UIAlertViewalloc]initWithTitle:@&qu ...

  6. .net 文件上传大小的设置

    直接在配置文件web.config 中进行如下配置,主要需要明白的就是 配置的 单位是 Byte,  所以一定计算清楚,不然会在这里纠结很久!!! <configuration> < ...

  7. Java的书写格式,标识符及命名规则,注释

    Java的书写格式,标识符及命名规则,注释 1.Java语言的书写格式(约定成俗) 1) 大括号要对齐(左大括号与句尾对其,后面大括号与句头对齐),并且成对写 2) 左大括号前面有空格 3) 遇到左大 ...

  8. python奇偶数求和

    #求100内奇数和while\for..in循环 sum = 0 i = 1 while i <= 100: sum += i i += 2 print(sum) sum = 0 for i i ...

  9. 【实战Java高并发程序设计 2】无锁的对象引用:AtomicReference

    AtomicReference和AtomicInteger非常类似,不同之处就在于AtomicInteger是对整数的封装,而AtomicReference则对应普通的对象引用.也就是它可以保证你在修 ...

  10. 【二】jekyll 的使用

    本系列有五篇:分别是 [一]Ubuntu14.04+Jekyll+Github Pages搭建静态博客:主要是安装方面 [二]jekyll 的使用 :主要是jekyll的配置 [三]Markdown+ ...