【发布时间】:2016-12-03 20:07:25
【问题描述】:
全部! bootstrap-select可以选择组吗?
这意味着当我选择一个组时,它可以通过 jquery 自动选择所属组项(optgroup)
对于 bootstrap-select 是不允许选择的! 所以我用其他方式使它像一个组..
<select class="selectpicker" id="join_person" multiple>
<option id="A">group1</option>
<option class="A" id="1">andy</option>
<option class="A" id="2">peter</option>
<option class="A" id="3">amy</option>
<option id="B">group2</option>
<option class="B" id="4">kelly</option>
<option class="B" id="5">tim</option>
</select>
And i need it.. when select the group ,it will not select itself ,contrarily to select all the same class with the group id ...
并将选定的项目 id 推送到一个数组!
现在我只能获得所有选定的项目....对我的情况有什么想法吗... 太谢谢你了
var arr = new Array();
$('#join_person').on('change', function(){
$(this).find("option").each(function()
{
if($(this).is(":selected"))
{
id = $(this).attr("id");
class_dept = $(this).attr("class");
if(id == class_dept){
//do something
}
if(arr.indexOf(id) == -1)
{
arr.push(id);
}
}
else
{
id = $(this).attr("id");
arr = jQuery.grep(arr, function(value) {
return value != id;
});
}
});
alert("Last selected : " + arr[arr.length-1] +" | array_item:"+ arr);
});
【问题讨论】:
-
也许你应该使用
<optgroup label="group1"><select ...></optgroup>而不是<option id="A">group1</option>? -
是的,但问题是标签
标签: jquery html bootstrap-select optgroup