Jquery toggle event is messing with checkbox value

前端 未结 10 1056
暗喜
暗喜 2020-11-29 02:01

I\'m using Jquery\'s toggle event to do some stuff when a user clicks a checkbox, like this:

$(\'input#myId\').toggle(
function(){
//do stuff  
},
function()         


        
10条回答
  •  情歌与酒
    2020-11-29 03:04

    $('input#myId').toggle(
      function(e){
        e.preventDefault();
        //do stuff      
        $(this).attr('checked', 'true');
      },
      function(e){
        e.preventDefault();
        //do other stuff        
        $(this).attr('checked', 'false');
      }
    );
    

提交回复
热议问题