[英]How to set select value in select2 plugin - jquery
我使用此代碼插入數據以使用select2
插件select
元素:
$.ajax({
type: "POST",
url: "ws.asmx/GetEvrakGrup",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (dc, status) {
jsonData = JSON.parse(dc.d);
$("#selectId").select2({
data: jsonData
});
},
error: function () { alert("This is an Error");}
});
在我想在這個選擇中設置一個值但它不起作用之后:
$("#selectId").val(81);
試試這個:
$("#selectId").val(81).trigger('change');
而不是
$("#selectId").val(81);
試試下面的代碼:
var $example = $("#selectId").select2();
$example.val(81).trigger("change");
$("#MyDropdownList").select2("trigger", "select", { data: { id: theID, text: theText } });
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.