简体   繁体   English

增加点击值

[英]Increase a value on a click

Every time I click on a button I want its z-index to increase one by one. 每次我点击一个按钮,我都希望它的z-index逐一增加。 How can I do it? 我该怎么做?

$('#Box').css('z-index', 'newindex');

对于jQuery 1.6及更高版本,请使用:

$('#Box').css('z-index','+=1');

尝试:

$('#Box').css('z-index',$('#Box').css('z-index') + 1);

Read the index. 阅读索引。 Add one to the index. 在索引中添加一个。 Reset the index with the new value. 使用新值重置索引。

var myElem = $('#Box');
var currentIndex = myElem.css('z-index') || 0;
myElem.css('z-index', currentIndex+1);

You can use jQuery's .css method both to get and set a particular value. 您可以使用jQuery的.css方法来获取设置特定值。

Since you want to take the current value and increment it, you would first use $('#Box').css('z-index') to get the value, then you would increment it and pass it to $('#Box').css('z-index', newvalue) . 因为你想获取当前值并递增它,你首先要使用$('#Box').css('z-index')来获取值,然后你将它递增并传递给$('#Box').css('z-index', newvalue)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM