I want to be able to set the default/selected value of a select element using the JQuery Select2 plugin.
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- How to fix IE ClearType + jQuery opacity problem i
- void before promise syntax
- jQuery add and remove delay
One way to accomplish this is...
So basically you first initalize the plugin then specify the default value using the 'val' parameter. The actual value is taken from the specified option, in this case #1. So the selected value from this example would be "bar".
Hope this is useful to someone else.
Don't know others issue, Only this code worked for me.
For 4.x version
to select value with INDEX
to select nothing (show placeholder if it is)
You should actually do this...intialise and then set the value..well this is also the way it worked for me.
For ajax select2 multiple select dropdown i did like this;
How is this?
Markup
JavaScript