[英]React MUI Multiple Select with Checkboxes not Check marking Initial Selected Options
[英]JQuery/Grails marking multiple options/values as selected in multiple select box
我有多個選擇:
<select type="text" name="specialTypeInd" id="specialTypeInd" multiple>
<option value="">None</option>
<option value="I">International</option>
<option value="M">Minority</option>
<option value="S">Study Abroad</option>
</select>
以前,我只是基於單個值來選擇單個選擇選項:
document.getElementById('specialTypeInd').value = hashNames[item][13]
其中hashNames [item] [13] =單個值(例如I),而select只是單個選擇框。
現在,我需要將其作為多選,但我仍然需要通過執行以下操作將它們標記為已選中:
document.getElementById('specialTypeInd').value = hashNames[item][13]
但是現在hashNames [item] [13]看起來像是單個值(例如I),也可能是多個值(例如I,S)。
對如何實現這一目標有幫助嗎?
我最終找到了如下所示的解決方案:
$.each(hashNames[item][13].split(","), function(i,e){
$("#specialTypeInd option[value='" + e + "']").prop("selected", true);
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.