Select2 是一個 jQuery 插件,提供可自訂的選擇框小工具。在本文中,我們將探討如何在 Select2 中設定預選值。
<code class="html"><input type="hidden" name="programid" id="programid" class="width-500"></code>
<code class="html"><select id="mySelect2" name="mySelect2[]"> <option value="TheID" selected="selected">The text</option> </select></code>
<code class="javascript">var $newOption = $("<option selected='selected'></option>").val("TheID").text("The text"); $("#mySelect2").append($newOption).trigger('change');</code>
<code class="javascript">$("#mySelect2").val(5).trigger('change');</code>
以上是如何在 Select2 中預先選擇值:版本 4 及以下版本的指南?的詳細內容。更多資訊請關注PHP中文網其他相關文章!