jquery - 当我完成 onclick show div 时隐藏按钮

标签 jquery onclick hide

我绝对是 jquery 的初学者。我正在使用谷歌来学习,但我找不到如何解决这个简单的问题。

我用一个按钮连续显示 div,但我想在没有更多 div 可显示时隐藏显示按钮。

这是代码:

$('#show').on('click', function() {
    if (index + 1 > max) {
        // Here, I suppose, I need to hide the button
    } else {
        if (index < max - 1) {
            index++;
            $('.container > div:eq(' + index + ')').show();
        }

在这里您可以看到示例

http://jsfiddle.net/vcARq/

提前致谢,对我的英语感到抱歉;)

最佳答案

基本上你需要在完成运行这样的函数时执行此操作

var index = -1;
var max = $('.container > div').length;
$('#show').on('click', function() {
        if (index < max - 1) {
            index++;
            $('.container > div:eq(' + index + ')').show();
        }
}, function () {
$(this).hide();
});

这应该适合你

关于jquery - 当我完成 onclick show div 时隐藏按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14423837/

相关文章:

javascript - 使用 javascript 附加输入类型

javascript - 关闭下拉菜单时将 div 移回原始位置

jquery - 使用 Am 图表隐藏/显示和调整问题大小

python - 如何使用代码在Python中删除Mayavi工具栏

javascript - 在 Vue 2.1 中使用另一个下拉列表动态更新一个下拉列表

javascript - 将谷歌货币转换器应用于页面上的所有价格

javascript - 如何使用jquery获取下一个节点?

android - 捕获 ListView 中的 TextView 点击

javascript - jQuery - 在按钮单击时淡入和淡出不同的元素

ios - 隐藏搜索显示 Controller 的搜索栏