我目前有一个 HTML 按钮,代码如下:
<form id="tfnewsearch" method="get" >
<input type="text" id="search_query" name="q" size="21" maxlength="120"><input type="button" id="search_button" name="search" value = "Search"onclick="doSearch(this.form.q)">
</form>
仅当我单击提交按钮时,函数“doSearch()”才起作用。如果我只按 Enter 键就必须工作,我必须做哪些更改?
最佳答案
<form id="tfnewsearch" method="get" onsubmit="doSearch()" >
只需将 onclick 更改为 onsubmit 并将其附加到您的表单即可!
关于JavaScript Html 按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27574934/