您的位置:首页 > Web前端 > BootStrap

Bootstrap 的select控件怎么选中或是异步刷新。

2014-12-17 14:07 309 查看
在异步刷新需要更新某个Bootstrap框架的Select控件,为其添加一个<option>,或是重新选中某个值时,会发现隐藏的select框的值修改了,但是前面显示选中的值还是不变,就需要用下面的方法。

先前在网上搜了好久,试了这篇文章里(点击打开链接)的两种方法,虽然实现了,但是很繁琐。

1. 通过$(this).removeAttr('selected'), 然后用$().trigger('liszt:updated'),就能把前端的代码改变了。

$("#mdisplaychart").find("option").each(function(){
$(this).removeAttr("selected");
});
$("#mdisplaychart").find("option").each(function(){
if(key == $(this).val()){
$(this).attr("selected","selected");
return false;
}
});
$("#mdisplaychart").trigger("liszt:updated");
$("#mdisplaychart").val(key);

2. 通过removeChosen()和chosen() 这两个方法可以实现。

$("#roadmapYearSelect").removeChosen();
$("#roadmapYearSelect").append("<option value=''>"+dropDrownInitValue+"</option>" + data);
$("#roadmapYearSelect").chosen();
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐