简体   繁体   English

SumoSelect 取消选择其他选项

[英]SumoSelect Unselect the other option

I want to unselect all the other option when i selected the option with value 0. On the other way, I need to unselect the option with value 0 when i select other value that is not 0. Please help me, below are my code.当我选择值为 0 的选项时,我想取消选择所有其他选项。另一方面,当我选择其他非 0 值时,我需要取消选择值为 0 的选项。请帮助我,下面是我的代码。

<script type="text/javascript">
    $(document).ready(function() {
       $('.sumomultiple').SumoSelect();
       $('.sumomultiple')[0].sumo.selectItem("0");
   });
</script>

<select id="st_type" class="sumomultiple table-group-action-input form-control" multiple="multiple" placeholder="Unselect All" onchange="$('#s_transtype').val($(this).val())">
    <option value="0">Unselect All</option>
    <option value="23">A</option>
    <option value="24">B</option>
    <option value="25">C</option>
</select>

$('#st_type').change(function(){

 // Please Help Here

});

I already try many ways i still have no idea how to do it, PLease help me.我已经尝试了很多方法我仍然不知道该怎么做,请帮助我。 Thank you very much...非常感谢...

This behaviour is built in to SumoSelect, there is no need to write it yourself.此行为内置于 SumoSelect,无需自己编写。 Use the selectAll option in the settings to enable it:使用设置中的selectAll选项来启用它:

 jQuery(function() { $('.sumomultiple').on('change', function() { $('#s_transtype').val($(this).val()) }).SumoSelect({ selectAll: true }); });
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.sumoselect/3.0.2/jquery.sumoselect.min.js"></script> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jquery.sumoselect/3.0.2/sumoselect.min.css" /> <select id="st_type" class="sumomultiple table-group-action-input form-control" multiple="multiple" placeholder="Unselect All"> <option value="23">A</option> <option value="24">B</option> <option value="25">C</option> </select> <input type="text" readonly="true" id="s_transtype" />

I'd suggest reading the library documentation and viewing the examples to understand more about the features available.我建议阅读库文档并查看示例以了解有关可用功能的更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM