:checked 选择器用于选择所有选中的复选框、单选按钮和 select 元素的选项。
注意:要仅检索 select 元素的选定选项,请使用 :selected 选择器。
句法:
$(":checked")
下面的示例说明了 jQuery 中的 :checked 选择器:
示例 1:此示例将 CSS 应用于所有选中的元素(在此示例中为复选框)。
`
jQuery | :checked Selector
$(document).ready(function() {
$(":checked").wrap("");
});
form {
font-weight: bold;
font-size: 25px;
color: green;
}
#
jQuery | :checked Selector
GeeksForGeeks_1
GeeksForGeeks_2
GeeksForGeeks_3
`
输出:
示例 2:此示例在单选按钮上使用选中的选择器。
`
jQuery | :checked Selector
$(document).ready(function() {
$(":checked").wrap("");
});
form {
font-weight: bold;
font-size: 25px;
color: green;
}
#
jQuery | :checked Selector
GeeksForGeeks_1
GeeksForGeeks_2
GeeksForGeeks_3
`
输出:
!
发表评论