對于普通的 html 元素,您可以通過表單獲取該元素的值。 function handleSubmit(event) { event.preventDefault() const formData = new FormData(e.target) console.log(formData.get("test")) // logs the value of the html element with the name "test" }<form onSubmit={handleSubmit}> <input name="test" /> <button type="submit">Submit</button></form>表單將分配一個鍵“測試”表單提交時輸入內容的值。我的問題:有沒有辦法讓此功能與語義 UI 下拉菜單一起使用?下面是我認為可行的理想情況,但我知道不行,因為該組件是其他元素的包裝器。 function handleSubmit(event) { event.preventDefault() const formData = new FormData(e.target) console.log(formData.get("test")) // logs the value of the html element with the name "test" }<form onSubmit={handleSubmit}> <Dropdown name="test" selection options={ [{key: '1', text: 'text', value: '1'}] }/> <button type="submit">Submit</button></form>提交表單時,在該下拉列表中選擇的任何值都會放入 formData 中名為“test”的鍵中。如果未選擇任何值,則為鍵“test”賦予未定義的值。這可能嗎?我還有另一個使用基本 html 選擇器的工作,但不想更改很多已經編寫的代碼。
有沒有辦法為語義 UI React Dropdown 提供 html“名稱”屬性
GCT1015
2023-09-14 18:02:05