Home > Web Front-end > JS Tutorial > body text

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

WBOY
Release: 2016-05-16 16:47:32
Original
1153 people have browsed it

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.
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template