Home > Article > Web Front-end > How to determine whether a checkbox is selected in jquery
Jquery method to determine whether the check box is selected: You can use the prop method to determine, such as [$(selector).prop("checked");]. The prop method is used to obtain the attribute value of the first element in the matched element set.
The operating environment of this tutorial: Windows 10 system, jquery version 2.2.4. This method is suitable for all brands of computers.
(Recommended tutorial: jquery video tutorial)
Introduction to judgment method:
1. Attribute acquisition method
$(selector).prop("checked");
2. Selector matching method
$(selector).is(":checked");
The function of the prop() method: Get the attribute value of the first element in the matched element set.
The prop() method obtains the Properties property.
Code implementation:
<!-- js --> $("#test").click(function () { console.log($(this).prop("checked")); //属性 console.log($(this).is(":checked")); //选择器 console.log($(this).get(0).checked); //原生 })
For more programming-related knowledge, please visit: Programming Learning! !
The above is the detailed content of How to determine whether a checkbox is selected in jquery. For more information, please follow other related articles on the PHP Chinese website!