jQuery: Test if checkbox is NOT checked

前端 未结 18 977
太阳男子
太阳男子 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条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-02 07:52

    I think the easiest way (with jQuery) to check if checkbox is checked or NOT is:

    if 'checked':

    if ($(this).is(':checked')) {
    // I'm checked let's do something
    }
    

    if NOT 'checked':

    if (!$(this).is(':checked')) {
    // I'm NOT checked let's do something
    }
    

提交回复
热议问题