,我与你的代码,这可能会或可能不会是一个问题,就是你缺少的数据参数注意到的第一件事你jQuery on
事件。您还打算将您的活动应用到document.body
而不是document
。
$(document.body/*changed*/).on('click', '.icon-layer-up', {}/*added*/, function() {
接下来,你总是设置currentIndex
到auto
再到0
,而不是检查,看它是否等于auto
。
if (currentIndex ==/*fixed*/ "auto") {
此外,您在最初设定currentIndex
作为一个字符串,它会试图增加它当字符串只转换为数字,你的方式。您必须先尝试将其转换为Number
,然后检查以确保它是Number
,然后然后对其进行增量。
这么干脆固定的代码应该是:
$(document.body).on('click', '.icon-layer-up', {}, function() {
console.log($(this).parent(".ui-wrapper").css("z-index"));
var currentIndex = Number($(this).parent(".ui-wrapper").css("z-index"));
if (isNaN(currentIndex)) { // if is not a number, set it to 0
currentIndex = 0;
}
var num = currentIndex++;
$(this).parent(".ui-wrapper").css("z-index", num);
});
接下来,确保你阅读z-index
,并了解它是如何工作的。 z-index
将不会应用于static
的默认position
的元素。尝试将您的元素设置为position: relative;
,您尝试应用z-index
。
参考z-index
:
Understanding CSS z-index
Adding z-index
在这种情况下使用
'VAR NUM = ++ CURRENTINDEX; .'增量+分配值 –