jQuery function execute on Button Click and Enter/Return (key)

后端 未结 3 1725
盖世英雄少女心
盖世英雄少女心 2021-02-08 23:54

I\'m trying to create a little search box that allows you to search Twitter based on the keyword you enter in the input field. While it\'s work, it only works if you press the S

3条回答
  •  南方客
    南方客 (楼主)
    2021-02-09 00:46

    If you want place event with not obtrusive js then you can use also this system:

    $("#element").keydown(function(event) {
    if (event.keyCode == 13) {
        // do stuff
    }
    

    also if you have a submit button, this is an alternative, #element must be the text field where you want catch the event.

    reference to this: answer

提交回复
热议问题