Checkbox inside an anchor click behavior

前端 未结 4 756
逝去的感伤
逝去的感伤 2021-01-12 14:55

Consider following snippet:



    
        

        
4条回答
  •  暖寄归人
    2021-01-12 15:48

    Well, it looks like a known Firefox bug, which leads to following link on checkbox click regardless of handlers' code. As a bit dirty workaround one can use:

    var checkbox = $('');
    checkbox.prependTo($('#a'));
    checkbox.click(function(e) {
        setTimeout(function() { checkbox.prop('checked', !checkbox.prop('checked')); }, 10);       
        // do something useful on clicking checkbox and but not surrounding link
        return false;
    });
    

提交回复
热议问题