我在我的專案中使用 html 下拉選單。如何在快速服務器中獲取選擇值?
<div class="mb-3">
<label for="kk" class="form-label">Designation</label>
<select class="form-select" name="picker" aria-label="Default select example" id="kk">
<option selected>Select</option>
<option value="1">Proffesor</option>
<option value="2">Associate Proffessor</option>
<option value="3">Lab Assistant</option>
</select>
</div>
在我的發布請求處理方法中,我使用此代碼來獲取值:
const f = req.body.picker;
這給了我的是下拉串列中所選值的索引,例如 0、1、2 等,而不是教授、副教授、實驗室助理等實際值。
uj5u.com熱心網友回復:
value當您發送請求時,您實際上會得到屬性中的內容。對于您想要的資料,您可以這樣做:
<div class="mb-3">
<label for="kk" class="form-label">Designation</label>
<select class="form-select" name="picker" aria-label="Default select example" id="kk">
<option value="" selected>Select</option>
<option value="Proffesor">Proffesor</option>
<option value="Associate Proffessor">Associate Proffessor</option>
<option value="Lab Assistan">Lab Assistant</option>
</select>
</div>
這就是你將得到的:
const f = req.body.picker; // -> "" or "Proffesor" or "Associate Proffessor" or "Lab Assistan"
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/411358.html
標籤:
