perform an action on checkbox checked or unchecked event on html form

前端 未结 7 2294
遥遥无期
遥遥无期 2020-12-06 09:40

I have a checkbox on a form which is unchecked by default as usual. now I want to perform two separated actions on checked and unchecked state of this checkbox.

this

7条回答
  •  南方客
    南方客 (楼主)
    2020-12-06 09:53

    Have you tried using the JQuery change event?

    $("#g01-01").change(function() {
        if(this.checked) {
            //Do stuff
        }
    });
    

    Then you can also remove onchange="doalert(this.id)" from your checkbox :)

    Edit:

    I don't know if you are using JQuery, but if you're not yet using it, you will need to put the following script in your page so you can use it:

    
    

提交回复
热议问题