select2 ajax 设置默认选中 selected
select2 设置默认选中
在数据源已经存在的情况
$('#mySelect2').val('1'); // Select the option with a value of '1'
$('#mySelect2').trigger('change'); // Notify any JS components that the value changed
在数据源是ajax 的情况下
var newOption = new Option(data.text, data.id, true, true);
$('#companyId').append(newOption).trigger('change');
详情请看官方文档
https://select2.org/programmatic-control/add-select-clear-items
· [翻译] 为什么 Tracebit 用 C# 开发
· 腾讯ima接入deepseek-r1,借用别人脑子用用成真了~
· Deepseek官网太卡,教你白嫖阿里云的Deepseek-R1满血版
· DeepSeek崛起:程序员“饭碗”被抢,还是职业进化新起点?
· RFID实践——.NET IoT程序读取高频RFID卡/标签