select2 option 設置disabled以及如何取消disabled屬性


問題: 需要對某一個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();    

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM