How jQuery determines whether check boxes are checked or not

  • 2020-03-30 03:01:05
  • OfStack

One of the things we're going to do today is assign a value to the input form when the checkbox is checked, and clear the form value when the checkbox is checked.

The effect is as follows:
< img SRC = "border = 0 / / files.jb51.net/file_images/article/201405/20140521161613.png? 2014421161639 ">  
Implementation source code: cyfID for the check box id
 
$("#cyfID").click(function(){ 
var ischeck=$(this).attr("checked"); 
if(ischeck==undefined){ 
//Clear the input box
alert(""); 
}else{ 
//Assign a value to the input field
alert("qq"); 
} 
}); 

$(this).attr("checked") is checked and undefined when checked.

Related articles: