表单选择器
语法 |
描述 |
返回值 |
:input |
匹配所有input,textarea,select和button元素 |
元素集合 |
:text |
匹配所有的单行文本框 |
元素集合 |
:password |
匹配所有密码框 |
元素集合 |
:radio |
匹配所有单选按钮 |
元素集合 |
:checkbox |
匹配所有复选框 |
元素集合 |
:submit |
匹配所有提交按钮 |
元素集合 |
:reset |
匹配许所有重置按钮 |
元素集合 |
:button |
匹配所有按钮 |
元素集合 |
:image |
匹配所有文件域 |
元素集合 |
:file |
匹配所有文件域 |
元素集合 |
示例代码如下:
验证
$(function () {
$(':text').blur(function () {
var str=$(this).val();
if(str.length<6){
$(this).next().html("数字不能少于6").css("color",'red')
}else {
$(this).next().html("")
}
})
})
//全选复选
$(function () {
$("#all").click(function () {
//attr一般用于改变静态属性
//prop一般用于频繁改变动态属性
$(":checkbox").prop("checked",this.checked)
})
})
//普通邮箱验证
$(function () {
$(":text").blur(function () {
var str=$(this).val()
if(str==null || str==''){
alert("不能为空")
}else if (!(str.indexOf("@")<str.indexOf(".")&&str.indexOf("@")>0)){
alert("不合法!")
}
})
})
表单过滤选择器
语法 |
描述 |
返回值 |
:enabled |
匹配所有可用元素 |
元素集合 |
:disabled |
匹配所有不可元素 |
元素集合 |
:checked |
匹配所有被选中元素(复选框,单选按钮,下拉列表) |
元素集合 |
:sele |