send data with ajax when pressing enter

前端 未结 5 1252
无人共我
无人共我 2021-01-16 16:59

i have a form like this :

5条回答
  •  我在风中等你
    2021-01-16 17:24

    I think it may be better to do this on the submit of the form. Browsers do the whole "enter" thing for you so you don't have to worry about it.

    Add id to the tag, and change the type from button to submit:

    
        
        
    
    

    Update you Javascript:

    $('#myForm').submit(function() {
            SendData();
    });
    

    Here is the JSFiddle

提交回复
热议问题