我有一个场景,如果 jquery 元素的属性值为 1 或更高,我需要对其进行排序
selectors = "a[href], area[href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), button:not([disabled]), iframe, object, embed, *[tabindex], *[contenteditable]";
var test = $("body").find(selectors);
现在我需要对测试变量进行排序(如果它的属性 tabindex 为 1 或更高)并按顺序放置在数组或对象的底部
注意:如果 tabindex 为 0,则不排序
为什么我需要这个?
这将帮助我确定正文中最后一个可聚焦的元素。
我知道这是一个有点棘手的问题,但我没有看到任何其他方法来找到最后一个可聚焦元素
最佳答案
试试这个:
selectors = "a[href], area[href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), button:not([disabled]), iframe, object, embed, *[tabindex], *[contenteditable]";
var test = $("body").find(selectors);
test.sort(function(a,b) {
// Replace b and a below if you wan't descending order
return $(b).attr("tabindex") < $(a).attr("tabindex");
});
关于javascript - 如果 Jquery 元素的属性值为 1 或更高,则对其进行排序并放置在底部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21947837/