想要使用字段中的输入提交数据并按“Enter”但不使用任何按钮(数据通过ajax)[重复]

This question already has an answer here:

<html><input id="test" type="text" /></html>
<script>
    $(function(){
        $("#test").keypress(function(event)
        {
            if ((event.charCode == 32) || (event.charCode == 64))
                alert("Working with space & @ but not with Enter");
        });
    });
</script>

Here is my code but it's not working for ascii of 'Enter' which is '13'

</div>

You can use "event.which" instead of "event.charCode" to get the key pressed. event.which will return 13 for enter key pressed.

Example:

var code = event.charCode || event.which;
 if(code == 13) { //Enter keycode
   //Do something
 }