Trigger an event on `click` and `enter`

前端 未结 7 2090
醉话见心
醉话见心 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:29
    $('#usersSearch').keyup(function() { // handle keyup event on search input field
    
        var key = e.which || e.keyCode;  // store browser agnostic keycode
    
        if(key == 13) 
            $(this).closest('form').submit(); // submit parent form
    }
    
    0 讨论(0)
提交回复
热议问题