[英]Is there a way to have a selected disabled option in select tag in react
我是新來的反應,通常在 HTML 我們會做<option selected disabled>Choose an option</option>
但是 selected 屬性似乎不適用於我的反應選項標簽。 這是代碼片段:
<select name="status" value={status} onChange={(e) => onChange(e)} required>
<option value="0">* Select Professional Status</option>
<option value="Developer">Developer</option>
<option value="Junior Developer">Junior Developer</option>
<option value="Senior Developer">Senior Developer</option>
<option value="Manager">Manager</option>
<option value="Student or Learning">Student or Learning</option>
<option value="Instructor">Instructor or Teacher</option>
<option value="Intern">Intern</option>
<option value="Other">Other</option>
</select>
我基本上想在下拉列表中放一個 label,謝謝
您可以為此使用React-select並添加占位符。
<Select options={options} placeholder="..."/>
實際上,要在反應中定位 select 元素中的元素,您應該嘗試 e.target.value 而不僅僅是 e。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.