我的選擇欄位過濾如下:
$("#asortyment option").filter(function() {
$(this).toggle($(this).text().toLowerCase().indexOf(value) > -1);
});
要更改選定的選項,我使用代碼:
function wiecej(){
var asort_select = document.getElementById("asortyment");
asort_select.selectedIndex = asort_select.selectedIndex 1;
$("#asortyment").trigger("change");
};
但問題是函式 wiecej 將選項更改為 next 但在未過濾的選擇中。
uj5u.com熱心網友回復:
使用 jQuery:visible偽類來匹配未過濾的元素。并用于:gt在當前選擇的選項之后啟動。
function wiecej() {
var asort_select = document.getElementById("asortyment");
let current = asort_select.selectedIndex;
let next = $(`#asortyment option:gt(${current}):visible`).first();
if (next.length > 0) {
$(asort_select).val(next.val()).change();
}
};
uj5u.com熱心網友回復:
過濾可見選項,然后更改選定的索引:
function wiecej(){
var asort_select = document.getElementById("asortyment");
var nextItem = $("#asortyment option:gt(" asort_select.selectedIndex ")").filter(function(){ return $(this).css('display') != 'none';}).first();
var nextIndex = 0;
if (nextItem.length > 0 ) {
nextIndex = nextItem[0].index;
} else {
var nextItem = $("#asortyment option").filter(function(){ return $(this).css('display') != 'none';}).first();
nextIndex = nextItem[0].index;
}
asort_select.selectedIndex = nextIndex;
$("#asortyment").trigger("change");
};
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/366034.html
標籤:javascript 查询
下一篇:追加更改未追加正確的專案
