Today I want to implement a function: assign a value to the input form when the check box is checked, and clear the form value when the check box is cancelled.
The effect is as shown:
Implementation source code: cyfID is the id of the check box
$("#cyfID").click(function(){
var ischeck=$(this).attr("checked");
if(ischeck==undefined){
//Clear the input box
alert("");
}else{
//Assign a value to the input box
alert("qq" );
}
});
The implementation principle is: $(this).attr("checked") is checked when the check box is checked, and it is checked when it is not checked. undefined.