文章目录
jQuery表单过滤器
jQuery表单过滤器主要是对form表单里面的inpu标签的过滤
<input type="text" value="文本框1">
<input type="text" value="文本框2" disabled>
<input type="text" value="文本框3">
<br>
<input type="checkbox" value="篮球">篮球
<input type="checkbox" value="运动" checked>运动
<input type="checkbox" value="跑步">跑步
<br>
<select>
<option value="html">html</option>
<option value="css">css</option>
<option value="javascript">javascript</option>
<option selected value="jQuery">jQuery</option>
</select>
效果
$(":text:enabled")
var in1 = $(":text:disabled");//选中text类型下的disabled的标签
in1.val("disabled");
$(":text:disabled")
var in2 = $(":text:enabled");//选中text类型下的enabled的标签
in2.val("enabled");
$(":checkbox:checked")
var in3 = $(":checkbox:checked");//选中checkbox类型下的checked的标签
alert(in3.val());
$(“select>option:selected”)
var in4 = $("select>option:selected");//选中select下的option标签下的selected的标签
alert(in4.val());
完整源码
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>表单过滤器</title>
<style>
body{
margin-top: 250px;
margin-left: 400px;
}
</style>
<script src="js/jquery-3.5.1.js"></script>
</head>
<body>
<input type="text" value="文本框1">
<input type="text" value="文本框2" disabled>
<input type="text" value="文本框3">
<br>
<input type="checkbox" value="篮球">篮球
<input type="checkbox" value="运动" checked>运动
<input type="checkbox" value="跑步">跑步
<br>
<select>
<option value="html">html</option>
<option value="css">css</option>
<option value="javascript">javascript</option>
<option selected value="jQuery">jQuery</option>
</select>
<script>
var in3 = $(":checkbox:checked");
alert(in3.val());
var in4 = $("select>option:selected");
alert(in4.val());
var in1 = $(":text:disabled");
in1.val("disabled");
var in2 = $(":text:enabled");
in2.val("enabled");
</script>
</body>
</html>