先看代码,后面详细解释:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script type="text/javascript" src="js/jquery-1.9.1.js" ></script>
<script>
$(function(){
//选择type类型进行更改
$("input[type=text]").css("background-color","aquamarine"); //选择name属性以z开头的
$("input[name^=z]").css("background-color","aquamarine"); //选择name属性以e结尾
$("input[name$=e]").css("background-color","aquamarine"); //选择name属性中有p
$("input[name*=p]").css("background-color","aquamarine"); //选择复合器,同时符合多种条件多种
$("input[type=text][name*=n]").css("background-color","aquamarine"); }) </script>
</head>
<body>
<center>
<h3>注册页面</h3>
<hr />
<form action="" method="get">
<table border="1px">
<tr height="35px">
<td width="150px">用户名:</td>
<td width="400px">
<input type="text" name="zuname" id="uname" value="" alt="用户名" οnblur="checkName()"/>
<span id="uname_span">*用户名必须是3-5位的汉字</span>
</td>
</tr>
<tr height="35px">
<td>密码:</td>
<td>
<input type="password" name="zpwd" id="pwd" value="" alt="密码" οnblur="checkPwd()"/>
<span id="pwd_span"></span> </td>
</tr>
<tr height="35px">
<td>手机号:</td>
<td>
<input type="text" name="zphone" id="phone" value="" alt="手机号" />
<span id="phone_span"></span>
</td>
</tr>
<tr height="35px">
<td>邮箱:</td>
<td>
<input type="text" name="email" id="email" value="" alt="邮箱" οnblur="checkEmail()" />
<span id="email_span"></span>
</td>
</tr>
<tr height="35px">
<td>颜色:</td>
<td>
<input type="color" name="scolor" id="" />
</td>
</tr>
<tr height="35px">
<td>爱好:</td>
<td>
<input type="checkbox" name="fav" id="" value="1" />唱歌
<input type="checkbox" name="fav" id="" value="2" />睡觉
<input type="checkbox" name="fav" id="" value="3" />LOL<br />
<input type="checkbox" name="fav" id="" value="4" />旅游
<input type="checkbox" name="fav" id="" value="5" />高尔夫
<input type="checkbox" name="fav" id="" value="6" />篮球 </td>
</tr>
<tr height="35px">
<td>籍贯:</td>
<td>
<select name="adress" id="sel" οnchange="checkAdress()">
<option value="0">--请选择--</option>
<option value="1">河南</option>
<option value="2">湖南</option>
<option value="3">海南</option>
<option value="4">云南</option>
</select> <span id="sel_span"></span>
</td>
</tr> <tr height="35px">
<td>验证码</td>
<td>
<input type="number" name="" id="yzm" value="" οnblur="checkYZM()"/>
<span id="yzm_span"></span>
<span id="yzm2_span"></span>
</td>
</tr> <tr height="35px">
<td>个人介绍:</td>
<td>
<textarea name="intro" rows="8" cols="30"></textarea>
</td>
</tr> <tr height="35px">
<td colspan="2" align="center">
<input type="checkbox" name="" id="check" value="" οnclick="checkAgree()">是否同一本公司协议
</td>
</tr>
<tr height="35px">
<td colspan="2" align="center">
<input type="submit" id="sub" value="注册" disabled="true"/>
</td>
</tr>
</table>
</form>
</center> </body>
</html>

选择type属性是text的标签:(类似于 $(":text"))

$("input[type=text]").css("background-color","aquamarine");

选择name属性以z开头的:(开头符号 ^)

$("input[name^=z]").css("background-color","aquamarine");

选择name属性以e结尾:(结尾符号 $)

$("input[name$=e]").css("background-color","aquamarine");

选择name属性中有p:(包含,含有 符号:*)

$("input[name*=p]").css("background-color","aquamarine");

选择复合器,同时符合多种条件多种:

$("input[type=text][name*=n]").css("background-color","aquamarine");
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script type="text/javascript" src="js/jquery-1.9.1.js" ></script>
<script>
$(function(){ //获取form表单的所有表单项
var inp=$(":input").length;
//alert(inp); //获取input标签中type属性是text
$(":text").css("background-color","darkblue");
//等同于:
$("input[type=text]").css("background-color","darkblue"); //获取input标签中checked属性
var val=$("input:checked");
//alert(val.val()); //获取input标签中属性disabled
var dd=$("input:disabled");
alert(dd.val()); //获取select中有selected属性。
var val=$("select option:selected");
//alert(val.val()); }) </script>
</head>
<body>
<center>
<h3>注册页面</h3>
<hr />
<form action="" method="get">
<table border="1px">
<tr height="35px">
<td width="150px">用户名:</td>
<td width="400px">
<input type="text" name="zuname" id="uname" value="" alt="用户名" οnblur="checkName()"/>
<span id="uname_span">*用户名必须是3-5位的汉字</span>
</td>
</tr>
<tr height="35px">
<td>密码:</td>
<td>
<input type="password" name="zpwd" id="pwd" value="" alt="密码" οnblur="checkPwd()"/>
<span id="pwd_span"></span> </td>
</tr>
<tr height="35px">
<td>手机号:</td>
<td>
<input type="text" name="zphone" id="phone" value="" alt="手机号" />
<span id="phone_span"></span>
</td>
</tr>
<tr height="35px">
<td>邮箱:</td>
<td>
<input type="text" name="email" id="email" value="" alt="邮箱" οnblur="checkEmail()" />
<span id="email_span"></span>
</td>
</tr>
<tr height="35px">
<td>颜色:</td>
<td>
<input type="color" name="scolor" id="" />
</td>
</tr>
<tr height="35px">
<td>爱好:</td>
<td>
<input type="checkbox" name="fav" id="" value="0"/>唱歌
<input type="checkbox" name="fav" id="" value="1" checked="checked"/>睡觉
<input type="checkbox" name="fav" id="" value="2"/>LOL
<input type="checkbox" name="fav" id="" value="3"/>旅游
<input type="checkbox" name="fav" id="" value="4"/>高尔夫
<input type="checkbox" name="fav" id="" value="5"/>篮球 </td>
</tr>
<tr height="35px">
<td>籍贯:</td>
<td>
<select name="adress" id="sel" οnchange="checkAdress()">
<option value="0">--请选择--</option>
<option >河南</option>
<option >湖南</option>
<option selected="selected">海南</option>
<option >云南</option>
</select> <span id="sel_span"></span>
</td>
</tr> <tr height="35px">
<td>验证码</td>
<td>
<input type="number" name="" id="yzm" value="" οnblur="checkYZM()"/>
<span id="yzm_span"></span>
<span id="yzm2_span"></span>
</td>
</tr> <tr height="35px">
<td>个人介绍:</td>
<td>
<textarea name="intro" rows="8" cols="30"></textarea>
</td>
</tr> <tr height="35px">
<td colspan="2" align="center">
<input type="checkbox" name="" id="check" value="" οnclick="checkAgree()">是否同一本公司协议
</td>
</tr>
<tr height="35px">
<td colspan="2" align="center">
<input type="submit" id="sub" value="注册" disabled="true"/>
</td>
</tr>
</table>
</form>
</center> </body>
</html>

获取form表单的所有表单项和   $("input")   进行区别开, $("input") 表示获取表单元素是input的。

$(":input")

获取input标签中type属性是text:

$(":text").css("background-color","darkblue");

获取input标签中checked属性:

$("input:checked");

获取input标签中属性disabled:

$("input:disabled");

获取select中有selected属性:

$("select option:selected");

jQuery中的属性选择器的更多相关文章

  1. js进阶 10-6 jquery中的属性选择器有哪些

    js进阶 10-6 jquery中的属性选择器有哪些 一.总结 一句话总结: 1.第一遍能学会么? 一遍是肯定学不会的,要多学几遍,所以想着怎么加快速度,减少学习的遍数 2.属性选择器是干嘛的? 选择 ...

  2. jQuery入门(1)jQuery中万能的选择器

    jQuery入门(1)jQuery中万能的选择器 jQuery入门(2)使用jQuery操作元素的属性与样式 jQuery入门(3)事件与事件对象 jQuery入门(4)jQuery中的Ajax()应 ...

  3. jquery笔记之属性选择器 查找以某种条件开头的页面元素

    jquery笔记之属性选择器 查找以某种条件开头的页面元素 转载:http://www.blogbus.com/amyqiong-logs/78340326.html $("div[id]& ...

  4. js进阶 10-5 jquery中的层级选择器有哪些

    js进阶 10-5 jquery中的层级选择器有哪些 一.总结 一句话总结: 1.jquery中的层级选择器有哪些? 四种,后代,子代,兄弟,相邻兄弟 2.如何区别jquery中的层级选择器? 记住这 ...

  5. jquery中的属性和css

    jQuery中的属性用于获取或设置元素的属性 1.attr(),获取或设置所有相匹配的元素的属性值:removeAttr("attr"),移除所有相匹配的元素的属性 //html ...

  6. jQuery中的:input选择器

    jQuery中的:input选择器 jQuery中的:input选择器包含input, textarea, select 和 button这些标签. <!DOCTYPE html> < ...

  7. js进阶 11-3 jquery中css属性如何操作

    js进阶 11-3  jquery中css属性如何操作 一.总结 一句话总结:通过css()方法 1.attr和css是有交叉的,比如width,两者中都可以设置,那么他们的区别是什么? 其实通俗一点 ...

  8. jQuery中的属性过滤选择器(四、五):[attribute] 、[attribute=value]、[attribute!=value] 、[attribute^=value] 等

    <!DOCTYPE html> <html> <head> <title>属性过滤选择器</title> <meta http-equ ...

  9. jQuery选择器之属性选择器Demo

    测试代码: 06-属性选择器.html <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" &quo ...

随机推荐

  1. css3 mask遮罩动画(照明灯效果)

    <pre><!DOCTYPE html><html lang="en"><head><meta charset="U ...

  2. 大宇java面试系列(三):Redis常见面试题

    1. Redis 是什么?都有哪些使用场景? 我们先来理解经典的CAP理论: 一致性:是指从数据层面来看的一致性. 可用性:是指从系统层面的可用性. 容错性:是指从网络层面的的容错性. 数据库逐渐从关 ...

  3. 将 /u 转变为 utf-8 编码

    将 /u 转变为 utf-8 编码 PHP实例: $result = {"errno":-1,"message":"\u8bbf\u95ee\u5fa ...

  4. 通过canvas合成图片

    通过canvas合成图片 效果图 页面布局部分 两个图片以及一个canvas画布 <img src="https://qnlite.gtimg.com/qqnewslite/20190 ...

  5. pat 1050 String Subtraction(20 分)

    1050 String Subtraction(20 分) Given two strings S​1​​ and S​2​​, S=S​1​​−S​2​​ is defined to be the ...

  6. (二十九)golang--map

    map:是key-value数据结构,又称为字段或者关联数组,类似其它编程语言的集合: 基本语法:var 名称 map[键类型]值类型 key的类型可以是:bool.数字.string.指针.管道,还 ...

  7. 领扣(LeetCode)单词模式 个人题解

    给定一种 pattern(模式) 和一个字符串 str ,判断 str 是否遵循相同的模式. 这里的遵循指完全匹配,例如, pattern 里的每个字母和字符串 str 中的每个非空单词之间存在着双向 ...

  8. 让块元素在div中水平居中,并且垂直居中的五种方法

    在写代码前,先做下准备工作,写两个div,设置下div的大小,把小的div放在大的div里面.可以给小的div设置下颜色,方便观看. 方法一:写一个伪元素,将它设置为行内块元素,高度与父元素相同,写一 ...

  9. 红帽学习笔记[RHCE]网络配置与路由转发

    目录 网络配置基本的IPV4与IPV6 拓扑图 操作 新加一块网卡 将增加的网卡分别加到两台虚拟机上 在两台虚拟机上配置IPV4与 IPV6 配置域名访问 拓展路由转发 拓扑图 操作 关于网关设置 重 ...

  10. Java多线程编程(5)--线程间通信

    一.等待与通知   某些情况下,程序要执行的操作需要满足一定的条件(下文统一将其称之为保护条件)才能执行.在单线程编程中,我们可以使用轮询的方式来实现,即频繁地判断是否满足保护条件,若不满足则继续判断 ...