jQuery表单域属性过滤器用法分析
作者:bea
本文实例讲述了jQuery表单域属性过滤器用法。分享给大家供大家参考。具体分析如下: 表单内包含各种各样的表单域,使用表单域属性选择器可以很好的获取已被选中的单选按钮,复选框以及列表项,也可以根据是否可用从文档中查找表单域。 1. :checked选择器 用于选择所有被选中的表单域。格式: 代码如下: $("selector:checked")可以是input,radio和checkbox 2. :enabled选择器 用于选择所有可用的表单域,格式: 代码如下: $("
本文实例讲述了jQuery表单域属性过滤器用法。分享给大家供大家参考。具体分析如下:
表单内包含各种各样的表单域,使用表单域属性选择器可以很好的获取已被选中的单选按钮,复选框以及列表项,也可以根据是否可用从文档中查找表单域。
1. :checked选择器
用于选择所有被选中的表单域。格式:
代码如下:
$("selector:checked")
可以是input,radio和checkbox
2. :enabled选择器
用于选择所有可用的表单域,格式:
代码如下:
$("selector:enabled")
3. :disabled选择器
用于选择所有被禁用的表单域,格式:
代码如下:
$("selector:disabled")
4. :selected选择器
用于从列表框选择所有选中的option元素,格式:
代码如下:
$("selector:selected")
5. :hidden选择器
用于选择所有的不可见元素
代码如下:
$("selector:hidden")
6. :visible选择器
用于选择所有的可见元素
简单示例:
代码如下:
<!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=utf-8" />
<title>表单域属性过滤选择器应用示例</title>
<script type="text/javascript" src="jquery-1.7.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("input:checked").css("border", "1px solid red");
$("input:disabled").css("background", "#FCF");
$("input:enabled").val("可用文本框");
});
</script>
</head>
<body>
<h3 align="center">表单域属性过滤选择器应用示例</h3>
<table width="602" height="81" border="1">
<tr>
<td width="118">复选框:</td>
<td width="443"><input type="checkbox" checked="checked" />被选中的复选框
<input type="checkbox" checked="checked" />被选中的复选框
<input type="checkbox" />没有被选中的复选框
</td>
</tr>
<tr>
<td>可用文本框:</td>
<td><input type="text"/></td>
</tr>
<tr>
<td>不可用文本框:</td>
<td><input type="text" disabled="disabled" /></td>
</tr>
<tr>
<td>下拉列表</td>
<td>
<select name="test" >
<option>浙江</option>
<option>湖南</option>
<option selected="selected">北京</option>
<option selected="selected">天津</option>
<option>广州</option>
<option>湖北</option>
</select>
</td>
</tr>
</table>
</body>
</html>
效果图:
希望本文所述对大家的jQuery程序设计有所帮助。
有用 | 无用
表单内包含各种各样的表单域,使用表单域属性选择器可以很好的获取已被选中的单选按钮,复选框以及列表项,也可以根据是否可用从文档中查找表单域。
1. :checked选择器
用于选择所有被选中的表单域。格式:
代码如下:
$("selector:checked")
可以是input,radio和checkbox
2. :enabled选择器
用于选择所有可用的表单域,格式:
代码如下:
$("selector:enabled")
3. :disabled选择器
用于选择所有被禁用的表单域,格式:
代码如下:
$("selector:disabled")
4. :selected选择器
用于从列表框选择所有选中的option元素,格式:
代码如下:
$("selector:selected")
5. :hidden选择器
用于选择所有的不可见元素
代码如下:
$("selector:hidden")
6. :visible选择器
用于选择所有的可见元素
简单示例:
代码如下:
<!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=utf-8" />
<title>表单域属性过滤选择器应用示例</title>
<script type="text/javascript" src="jquery-1.7.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("input:checked").css("border", "1px solid red");
$("input:disabled").css("background", "#FCF");
$("input:enabled").val("可用文本框");
});
</script>
</head>
<body>
<h3 align="center">表单域属性过滤选择器应用示例</h3>
<table width="602" height="81" border="1">
<tr>
<td width="118">复选框:</td>
<td width="443"><input type="checkbox" checked="checked" />被选中的复选框
<input type="checkbox" checked="checked" />被选中的复选框
<input type="checkbox" />没有被选中的复选框
</td>
</tr>
<tr>
<td>可用文本框:</td>
<td><input type="text"/></td>
</tr>
<tr>
<td>不可用文本框:</td>
<td><input type="text" disabled="disabled" /></td>
</tr>
<tr>
<td>下拉列表</td>
<td>
<select name="test" >
<option>浙江</option>
<option>湖南</option>
<option selected="selected">北京</option>
<option selected="selected">天津</option>
<option>广州</option>
<option>湖北</option>
</select>
</td>
</tr>
</table>
</body>
</html>
效果图:
希望本文所述对大家的jQuery程序设计有所帮助。
有用 | 无用
猜你喜欢
您可能感兴趣的文章:
- JavaScript中的继承方式详解
- JavaScript中原型和原型链详解
- Node.js中的缓冲与流模块详细介绍
- javascript中var的重要性分析
- JavaScript设计模式之工厂模式和构造器模式
- js实现可兼容IE、FF、Chrome、Opera及Safari的音乐播放器
- 45个JavaScript编程注意事项、技巧大全
- JS实现判断碰撞的方法
- javascript异步编程代码书写规范Promise学习笔记
- jquery实现动态操作select选中
- JS操作HTML自定义属性的方法
- jQuery制作仿Mac Lion OS滚动条效果
- jQuery扁平化风格下拉框美化插件FancySelect使用指南
- javascript中定义类的方法详解
- JavaScript判断浏览器类型的方法
- javascript定时器完整实例
- jQuery搜索子元素的方法
- jQuery搜索同辈元素方法
- Jquery搜索父元素操作方法