jQuery: Test if checkbox is NOT checked

前端 未结 18 975
太阳男子
太阳男子 2020-12-02 07:12

I\'m having trouble figuring this out. I have two checkboxes (in the future will have more):

  • checkSurfaceEnvironment-1
  • checkSurface
18条回答
  •  -上瘾入骨i
    2020-12-02 08:09

    An alternative way:

    Here is a working example and here is the code, you should also use prop.

    $('input[type="checkbox"]').mouseenter(function() { 
        if ($(this).is(':checked')) {
            //$(this).prop('checked',false);
            alert("is checked");
        } else {
             //$(this).prop('checked',true);
            alert("not checked");
        }
    });​
    

    I commented out the way to toggle the checked attribute.

提交回复
热议问题