Home  >  Article  >  Web Front-end  >  The principle and example of jQuery determining whether a check box is checked_jquery

The principle and example of jQuery determining whether a check box is checked_jquery

WBOY
WBOYOriginal
2016-05-16 16:47:321151browse

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:
The principle and example of jQuery determining whether a check box is checked_jquery
Implementation source code: cyfID is the id of the check box

Copy code The code is as follows:

$("#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.
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