如何以编程方式更改select2值 [英] how to change select2 value programmatically
本文介绍了如何以编程方式更改select2值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在引导程序模式下有一个select2框,我想更改select2框的值,但是它不起作用.
I have a select2 box in bootstrap modal, I want to change the value of the select2 box but it didn't work.
我尝试了以前的帖子和结果中的每个解决方案,但没有一个能奏效.
I tried every single solution in previous posts and results but none of them got it work.
我使用了 select2 4.0.2 ,我进行了测试:
I use select2 4.0.2, I tested:
$('#select_id').val('val').trigger('change.select2');
$('#select_id').val('val').trigger('change');
$('#select_id').val('val').change()
它可以工作一到两次,然后(随机)停止工作
It works one or two times then it stops working (randomly)
仅当我将select2更改回3.x.x时,它才能正常工作
It works fine only when I change the select2 back to 3.x.x
推荐答案
$('#select_id').val('val').trigger('change');
是正确的方法,请参见此处
is the right way, see here
这篇关于如何以编程方式更改select2值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文