Home  >  Article  >  Web Front-end  >  How does jQuery determine whether a checkbox is checked? Is there any way

How does jQuery determine whether a checkbox is checked? Is there any way

云罗郡主
云罗郡主forward
2018-10-27 11:33:173656browse

The content of this article is about how jQuery determines whether the check box is checked? Is there any method that has certain reference value? Friends in need can refer to it. I hope it will be helpful to you.

The function implemented here is to assign a value to the input form when the check box is checked, and clear the form value when the check box is cancelled.

How does jQuery determine whether a checkbox is checked? Is there any way

Implementation source code: cyfID is the id of the check box

$("#cyfID").click(function(){ 
    var ischeck=$(this).attr("checked"); 
    if(ischeck==undefined){ 
        //清除输入框 
        alert(""); 
    }
    else{ 
        //给输入框赋值 
                 alert("qq"); 
    } 
});

The implementation principle is: when the check box is checked $(this).attr(" checked") is checked, and it is undefined when not checked.

The above is how jQuery determines whether a checkbox is checked? I hope you can gain something from all the methods. Please pay attention to the PHP Chinese website for more jQuery.

The above is the detailed content of How does jQuery determine whether a checkbox is checked? Is there any way. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:lvyestudy.com. If there is any infringement, please contact admin@php.cn delete