JQuery Bootstrap Multiselect插件-设置在multiselect下拉列表中选择的值 [英] JQuery Bootstrap Multiselect plugin - Set a value as selected in the multiselect dropdown

查看:710
本文介绍了JQuery Bootstrap Multiselect插件-设置在multiselect下拉列表中选择的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Boostrap Multiselect插件( http://davidstutz.de/bootstrap- multiselect/)如下

I am having a multiselect dropdown using the Boostrap Multiselect plugin (http://davidstutz.de/bootstrap-multiselect/) as below

<select id="data" name="data" class="data" multiple="multiple">
  <option value="100">foo</option>
  <option value="101">bar</option>
  <option value="102">bat</option>
  <option value="103">baz</option>
</select>

在页面加载时,我将得到一个值数组,如[101,102]. 我应该遍历数组并选择值(应该选中与ID对应的复选框). 请帮忙.

On load of page, i will get an array of value like [101,102]. I should iterate through the array and make the values selected(check boxes corresponding to the ids should be checked). Please help.

推荐答案

谢谢大家的回答.

以您的所有答案为指导,我使用以下代码解决了该问题:

Taking all of your answers as a guideline, I resolved the problem with the below code:

var valArr = [101,102];
i = 0, size = valArr.length;
for(i; i < size; i++){
  $("#data").multiselect("widget").find(":checkbox[value='"+valArr[i]+"']").attr("checked","checked");
  $("#data option[value='" + valArr[i] + "']").attr("selected", 1);
  $("#data").multiselect("refresh");
}

再次感谢您的支持.

这篇关于JQuery Bootstrap Multiselect插件-设置在multiselect下拉列表中选择的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆