[英]How to reset the select box values in Jquery sumoselect Multi select plugin
I am using Jquery sumoselect plugin for multiselection option. 我正在使用Jquery sumoselect插件进行多选选项。 I want to reset the values on click of some button.
我想通过单击某些按钮来重置值。
Here is my code: 这是我的代码:
<script src="//code.jquery.com/ui/1.11.2/jquery-ui.js"></script>
<script src="js/jquery.sumoselect.min.js"></script>
<link href="css/sumoselect.css" rel="stylesheet" />
<script type="text/javascript">
$(document).ready(function () {
window.asd = $('.SlectBox').SumoSelect({ okCancelInMulti: true });
});
Here is the function for reset of multiselect content 这是重置多选内容的功能
function clearContents()
{
$('select.SlectBox')[0].sumo.unload();
}
<select name="is_dist_handled" multiple="multiple" placeholder="Select" class="SlectBox">
<option value="Y">Yes</option>
<option value="N">No</option>
</select>
You can use the sumo.unSelectItem();
您可以使用
sumo.unSelectItem();
. 。 Source here
来源在这里
$(document).ready(function () {
$('.SlectBox').SumoSelect({ okCancelInMulti: true });
$('button').on('click', function(){
var num = $('option').length;
for(var i=0; i<num; i++){
$('.SlectBox')[0].sumo.unSelectItem(i);
}
});
});
Update 更新资料
To remove only the selected options 仅删除所选的选项
$('button').on('click', function () {
var obj = [];
$('option:selected').each(function () {
obj.push($(this).index());
});
for (var i = 0; i < obj.length; i++) {
$('.SlectBox')[0].sumo.unSelectItem(obj[i]);
}
});
This would be the possible option to unSelect all the selection: 这可能是取消选择所有选择的选项:
.unSelectAll()
Un selects all items in the list 取消选择列表中的所有项目
//Un select all items //取消选择所有项目
$('select.SlectBox')[0].sumo.unSelectAll();
This is working fine for me. 这对我来说很好。
('#Multi_Lead_Status')[0].sumo.unload();
$('#Multi_Lead_Status').val('');
$('#Multi_Lead_Status').SumoSelect({
search: true,
placeholder: 'Status',
csvDispCount: 2,
searchText: 'Search...'
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.