問題: 需要對某一個option設置為不可選,但是一些操作之后恢復可選狀態。
//獲取所有的要操作的option
var m_field_dom = Array.from($(".m-field").children("option")); m_field_dom.forEach(item=>{ var type = $(item).attr("data-type"); $(item).prop("disabled",false); if(val == "sum"){ if(type == "num"||type == "decimal"){ $(item).prop("disabled",true); }; } }); 關鍵一步:必須在改變disabled狀態之后,對select重新select2 $(".m-field").select2();