Trigger an event on `click` and `enter`

前端 未结 7 2098
醉话见心
醉话见心 2020-12-12 14:52

I have a searchbox on my site that. Currently, users must click the submit button next to the box to search via jquery\'s post. I would like to let users also press enter

7条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-12 15:12

    Something like this will work

    $('#usersSearch').keypress(function(ev){
        if (ev.which === 13)
            $('#searchButton').click();
    });
    

提交回复
热议问题