Jef*_*ick 6 javascript jquery multi-select multiselect.js
我一直在尝试没有成功让多选择按预期运行.我可以像下面这样包装multiSelect调用并且它可以工作,但由于某种原因,如果它没有像直接的示例代码那样包装,它就不起作用.
(function ($) {
$(function () {
$('#mySelectList').multiSelect();
})
})(jQuery);
Run Code Online (Sandbox Code Playgroud)
如果我可以打电话,我可以克服这种烦恼 $('#keep-order').multiSelect('select', 'whatIwant');
但是,如果我理解正确的话,由于范围的原因,调用multiselect select在其他地方不起作用.
如果有帮助的话,这就是我现在的意思.为了澄清,除了标有"不起作用"的位之外,以下内容将起作用.
这是html加载脚本:
<link type="text/css" href="~/css/multiselect/multiselect.css" rel="stylesheet" />
<link type="text/css" href="~/css/bootstrap.min.css" rel="stylesheet" />
<script type="text/javascript" src="~/Scripts/jquery-1.12.4.min.js"></script>
<script type="text/javascript" src="~/js/quicksearch/jquery.quicksearch.js"></script>
<script type="text/javascript" src="~/js/bootstrap/bootstrap.min.js"></script>
<script type="text/javascript" src="~/js/multiselect/multiselect.js"></script>
<script type="text/javascript" src="~/Scripts/myjavascript.js"></script>
Run Code Online (Sandbox Code Playgroud)
myjavascript.js的内容
// This is a combination of quicksearch and multiselect.
; (function ($) {
$(function () {
$('#mySelectList').multiSelect({
keepOrder: true,
selectableHeader: "<div class='searchTitle'>Select: Sap</div><input type='text' id='searchSelectable' class='search-input' autocomplete='off' placeholder='Search: Sap'>",
selectionHeader: "<div class='searchTitle'>Selection:</div><input type='text' class='search-input' autocomplete='off' placeholder='Search: Selection'>",
afterInit: function (ms) {
var that = this,
$selectableSearch = that.$selectableUl.prev(),
$selectionSearch = that.$selectionUl.prev(),
selectableSearchString = '#' + that.$container.attr('id') + ' .ms-elem-selectable:not(.ms-selected)',
selectionSearchString = '#' + that.$container.attr('id') + ' .ms-elem-selection.ms-selected';
that.qs1 = $selectableSearch.quicksearch(selectableSearchString)
.on('keyup', function (e) {
if (e.which === 40) {
that.$selectableUl.focus();
return false;
} else if (e.which === 86 && e.ctrlKey) { // Ctrl + V
// ############################################ //
// ######## The following does not work ######## //
// ############################################ //
$('#mySelectList').multiSelect('select', 'something');
});
$('#searchSelectable').val('');
return false;
}
});
that.qs2 = $selectionSearch.quicksearch(selectionSearchString)
.on('keydown', function (e) {
if (e.which === 40) {
that.$selectionUl.focus();
return false;
}
});
},
afterSelect: function () {
this.qs1.cache();
this.qs2.cache();
},
afterDeselect: function () {
this.qs1.cache();
this.qs2.cache();
}
});
// Hide everything until multiselect does its thing
$("#hideReady").show();
})
})(jQuery);
Run Code Online (Sandbox Code Playgroud)