0

我正在使用引導選擇插件(https://silviomoreto.github.io/bootstrap-select/)爲我的下拉多選框。取消選擇任何其他選項引導程序的默認選擇

我已啓用默認選項,當頁面加載時打勾。圖像下方

enter image description here

<select id="dataPicker" class="selectpicker" multiple> 
 
\t <optgroup > 
 
\t \t <option value="default" selected="selected">ALL</option> 
 
\t </optgroup> 
 
\t <optgroup "> 
 
\t \t <option value="failed">FAILED</option> 
 
\t \t <option value="running">RUNNING</option> 
 
\t \t <option value="completed">COMPLETED</option> 
 
\t </optgroup> 
 
</select>

在上面的代碼 「ALL」 將被默認地選擇。

我正在尋找一種行爲,當用戶選擇「ALL」以外的任何選項時,「ALL」會自動取消選擇。

請幫忙。

回答

0

將'data-actions-box =「true」'添加到您選擇的元素。

<select class="selectpicker" multiple data-actions-box="true"> 
     <option>Mustard</option> 
     <option>Ketchup</option> 
     <option>Relish</option> 
</select> 

https://silviomoreto.github.io/bootstrap-select/examples/#selectdeselect-all-options

如果你希望通過你的方法繼續,那麼你將需要添加的選擇項事件一個事件掛鉤並檢查,如果該項目是「全部」項目和手動取消選擇列表中的所有項目,反之亦然。

https://silviomoreto.github.io/bootstrap-select/methods/#selectpickerselectall