我希望每个“p”元素在单击按钮时显示。但它不起作用,请帮忙。
<script>
$(document).ready(function(){
$("p").hide();
$("button").click(function(){
$('p').each(function() {
//alert($(this).text());
var abc = $(this).text();
abc.next().show();
});
});
});
</script>
<button>Toggle</button>
<p>Hello</p>
<p>Good morning</p>
<p>Good after noon</p>
<p>Good evening</p>
<p>Good night</p>
<div></div>
最佳答案
$("p").hide();
$("button").click(function(){
$('p').each(function () {
if (!$(this).is(":visible")) {
$(this).show();
return false;
}
});
});
关于jquery - foreach 与 jquery 元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7572816/