您的位置:首页 > 其它

Select2 如何设置值?

2015-10-08 17:08 357 查看
I know if i have a select2 and i want to set one of the options, i can do run this code.
$(document).ready(function(){
$('#btn').change(function(){
$('#select').val(4).trigger("change")
});
});


Lets say i want to get the text of the option
<option value=4>California</option>


but if i want to set it based on the text not the value, how do i do it?

I tried doing
$("#select").select2(data.text(), "California");


but it didnt work.

How can i do this programatically in jquery or javascript.

Any help is appreciated
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: