Call a function on enter key press

后端 未结 5 1288
死守一世寂寞
死守一世寂寞 2020-12-14 14:46

How to call a function using knockout.js when enter key is pressed.. here is my code below.

ko.bindingHandlers.enterkey = {
init: function (element, valueAcc         


        
5条回答
  •  醉酒成梦
    2020-12-14 15:11

    And this worked for me, thanks to @DaafVader.

    in view:

    
    
    

    in javascript:

    $("#myInput").keyup(function (event) {
            if (event.keyCode == 13) {
                search();
            }
    });
    

    To put keyup event in your jquery event instead of knockout event reduced the complexity of the knockout viewmodel.

提交回复
热议问题