douzhuang1900 2013-04-14 21:36
浏览 13
已采纳

Javascript / html使用返回键提交表单?

I have a form which performs a javascript when submit is clicked. I can't seem to figure out how to do the same thing when the return key (13) is used.

HTML: (note MakeRequest() is a JS method which performs a request on another php page and returns results to JSresult.)

<form name="SearchForm">
Name: <input type = "text" name = "Name" id="Search"
placeholder="Search stuff here...">
<button type="button" id "Request" onClick="MakeRequest()"">Search</button>

</form>
div id="JSresult">
</div>
  • 写回答

2条回答 默认 最新

  • dongmei8760 2013-04-14 21:44
    关注

    Replace your button with a submit input and move the function to form onSubmit, instead of button onClick :

    <form name="SearchForm" onSubmit="MakeRequest();">
        Name: <input type = "text" name = "Name" id="Search" placeholder="Search stuff here..." />
        <input type="submit" id="Request" value="Search" />
    </form>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?