[英]How to trigger a submit action for an input element or form while pressing enter key?
有一個簡單的搜索欄(輸入字段),當我們按下 Enter 按鈕時,它應該觸發一個 onSubmit 動作
您可以使用 onKeyPress。 檢查這個: https://stackoverflow.com/questions/13987300/how-to-capture-enter-key-press
很簡單,在表單內有一個按鈕類型提交。 這是一個例子:
const onSubmit = () => {}
// ..
<form onSubmit={onSubmit}>
...
<button type="submit">Search</button>
...
</form>
您不需要使用 onKeyPress 事件。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.