JQuery determines whether checkbox is selected. jquerycheckbox
The methods provided in most articles on the Internet are ineffective, killing individuals. The method in this article is effective in the test. method 2 is recommended:
Method 1:
If ($ ("# checkbox-id") get (0). checked ){
// Do something
}
Method 2:
If ($ ('# checkbox-id'). is (': checked ')){
// Do something
}
Method 3:
If ($ ('# checkbox-id'). attr ('checked ')){
// Do something
}
How does jquery determine whether checkbox is selected?
$ (Document). ready (function (){
$ ("# Checkbox2"). click (function (){
If (!! $ ("# Checkbox2"). attr ("checked ")){
Alert ("ddd ");
}
});
});
Paste it and try again. The click (...) syntax is incorrect... $ ("# checkbox2"). click (){
How does jquery obtain the checkbox and determine whether to select it?
$ ("Input [type = 'checkbox']"). attr ('value ')
Returned result: 501
$ ("Input [type = 'checkbox']"). is (': checked ')
Returned results: Select = true, not selected = false