如何找到指定元素集合中最高的CSS z-index值,并将被点击的元素推到z-index顺序的顶部。
var elements = $('selector').click(function(){ $(this).css('z-index', max++); }),
max = Math.max.apply(Math, elements.map(function() {
return parseInt($(this).css('z-index'), 10) || 0;
}).get());
z-index
的值。
编辑:使用AndyE在聊天室提供的Math.max
计算最大z-index
的新方法:https://chat.stackoverflow.com/transcript/message/96656#96656