Three methods for jQuery to determine whether the checkbox is selected

web front end seven thousand and seventy-three 8 years ago (2017-02-16)

The check box selection status of forms is often judged in projects, and the following three common methods are summarized:


Method 1 (recommended):

 if($("#checkbox").is(":checked")) {     // do something }

Method 2:

 if ($("#checkbox").attr("checked")) {     // do something }

Method 3:

 if ($("#checkbox").get(0).checked) {     // do something }