knockout js radio button click event reset selection

后端 未结 3 1090
无人共我
无人共我 2021-02-13 02:46

I have bind \"checked\" and \"click\" event on a radio button list. But whenever a radio button is clicked, the selection does not stay. I must be doing something really wrong.

3条回答
  •  名媛妹妹
    2021-02-13 03:05

    From the click event documentation:

    By default, Knockout will prevent the click event from taking any default action.
    ...
    However, if you do want to let the default click action proceed, just return truefrom your click handler function.

    So your radio button is reset because of your click handler and to fix it you just need to return true at the end:

    click: function(){
       alert('Hi');
       return true;
    }
    

    Demo JSFiddle.

提交回复
热议问题