下面的代码在Firefox 31.0,IE 10和克罗默36.0.1985.143。但如果使用CTRL键,它也不能很好地工作。
$('select').bind("click", function (event, target) {
event.preventDefault();
var CurrentIndex = event.target.selectedIndex==undefined? $(event.target).index(): event.target.selectedIndex
var CurrentOption = $("option:eq(" + CurrentIndex+ ")", $(this));
if ($(CurrentOption).attr('data-selected') == undefined || $(CurrentOption).attr('data-selected') == 'false') {
$(CurrentOption).attr('data-selected', true);
}
else {
$(CurrentOption).prop('selected', false).attr('data-selected', false);
}
$("option", $(this)).not(CurrentOption).each(function (Index, OtherOption) {
$(OtherOption).prop('selected', ($(OtherOption).attr('data-selected') == 'true') ? true : false);
});
return false;
});
IM多选插件的jQueryUI的http://www.erichynds.com/blog/jquery-ui-multiselect-widget的忠实粉丝,这也将让人们进行筛选,并有选择“选择全部'选项 – haxxxton 2014-09-02 08:41:04
感谢您的评论,实际上,我不需要使用新图书馆就可以找到问题:) – user3584625 2014-09-02 08:47:13
您是否尝试使用鼠标的滚动按钮单击选项? :D实际上它不需要CTRL被按下 – 2014-09-02 09:38:54