我想通过单击按钮来逐个显示列表项目。jQuery最好的方法来逐个显示列表项目
这里是我的代码:
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script>
$(document).ready(function() {
$('ol > li').hide();
$('button').click(function() {
if ($('ol > li:first').is(':visible'))
$('ol > li:visible:last').next().show();
else
$('ol > li:first').show();
});
});
</script>
<button type="button">Show</button>
<ol>
<li>#1</li>
<li>#2</li>
<li>#3</li>
<li>#4</li>
<li>#5</li>
<li>#6</li>
</ol>
它的工作原理,但我敢肯定,可以优化。什么是最好的方法?
在此先感谢!
这个问题可能是更适合HTTP: //codereview.stackexchange.com/ – David 2013-04-23 08:54:13
将变量设置为显示的最后一项,而不是使用选择器。 – Barmar 2013-04-23 08:57:36
@David谢谢,我不知道这一个。我会在下次使用它。 – 2013-04-23 09:04:11