How to submit a form when the return key is pressed?

前端 未结 15 1026
既然无缘
既然无缘 2020-11-28 04:25

Can someone please tell me how to submit an HTML form when the return key is pressed and if there are no buttons in the form? The submit button is not there

15条回答
  •  醉梦人生
    2020-11-28 05:09

    Here is how I do it with jQuery

    j(".textBoxClass").keypress(function(e)
    {
        // if the key pressed is the enter key
        if (e.which == 13)
        {
            // do work
        }
    });
    

    Other javascript wouldnt be too different. the catch is checking for keypress argument of "13", which is the enter key

提交回复
热议问题