jQuery :checked 选择器
实例
选择所有选中的元素(复选框或单选按钮):
<!DOCTYPE html><html><head><script src="https://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script><script>$(document).ready(function(){$(":checked").wrap("<span style='background-color:red'>");});</script></head><body><form action="">姓名: <input type="text" name="user"><br>我有一辆自行车: <input type="checkbox" name="vehicle" value="Bike"><br>我有一辆汽车: <input type="checkbox" name="vehicle" value="Car"><br>我有一架飞机: <input type="checkbox" name="vehicle" value="Airplane"><br><input type="submit"></form><p>注意:我们使用 jQuerys .wrap 方法高亮显示所选元素,因为 Firefox 不支持复选框的背景色。</p></body></html>
定义与用法
:checked 选择器选择所有选中的复选框或单选按钮。
语法
$(":checked")