[英]jquery to show div one by one each click event
This is my code : 这是我的代码:
<script type="text/javascript">
$(document).ready(function(){
$('.toAdd').hide();
$('#add').click(function () {
var i = 0;
$('.toAdd').each(function () {
if ($(this).show()) {
i++;
}
});
});
});
</script>
<div id=add><input type="button" value="click"/>
</div>
<div id="toAdd">
<label>1</label>
</div>
<div id="toAdd">
<label>2</label>
</div>
<div id="toAdd">
<label>3</label>
</div>
<div id="toAdd">
<label>4</label>
</div>
In this code i need to show div one by one for each click event but its not working? 在此代码中,我需要为每个点击事件一个一个显示div,但它不起作用?
在您的div中,将id =“ toAdd”更改为class =“ toAdd”
Replace <div id="toAdd"> with <div class="toAdd">
将<div id="toAdd"> with <div class="toAdd">
and do this 并做到这一点
$('.toAdd').each(function () {
if (!$(this.is(":visible"))) {
$(this).show();
break;
}
});
change id to class, like other have said and if you need to cycle the show/hide. 像其他人所说的那样,如果需要循环显示/隐藏,则将id更改为class。 then this might come handy 那么这可能会派上用场
$('.toAdd').hide();
var i = 0;
$('#add input').click(function () {
i=(i >= 4)?0:i;
//or if(i >= 4){ i=0;}
$('.toAdd').eq(i).show().siblings().not(':first').hide();
i++;
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.