How do I use event.preventDefault with KnockoutJs click event handlers?

前端 未结 2 617
无人共我
无人共我 2021-02-18 12:57

I have the following table row as a script template in KnockoutJs:

    

        
相关标签:
2条回答
  • 2021-02-18 13:16

    If you have jQuery referenced, then you can safely call e.stopImmediatePropagation(); in your handler, as it is passed the jQuery event object. If you are not using jQuery, then you could still do something like:

    e.cancelBubble = true;
    if (e.stopPropagation) e.stopPropagation();
    

    http://jsfiddle.net/rniemeyer/mCxjz/

    0 讨论(0)
  • 2021-02-18 13:21

    As per @Benoit Drapeau's comment:

    In more recent versions of Knockout you use clickBubble: false. e.g.

    <td data-bind="click: myFunction, clickBubble: false"> </td>
    

    http://knockoutjs.com/documentation/click-binding.html

    0 讨论(0)
提交回复
热议问题