Home  >  Article  >  Web Front-end  >  How to determine whether a checkbox is selected in jquery

How to determine whether a checkbox is selected in jquery

王林
王林Original
2020-11-26 10:48:534773browse

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.

How to determine whether a checkbox is selected in jquery

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn