删除第一步 jQuery 步的上一个按钮

Removing Previous Button on First Step jQuery Steps

我正在使用我的站点注册向导的 jQuery 步骤,效果非常好,除了在第一步我得到上一个按钮,这真的没有意义,因为没有以前的内容.

我查看了API中的onInit()函数,但是没有enablePreviousButton的设置,只有enableFinishButtonenableCancelButton.

有什么方法可以删除第一步的“上一步”按钮吗?

请求代码:

$("#register-form").steps({
    headerTag: "h3",
    bodyTag: "fieldset",
    autoFocus: true,
    onInit: function (event, current) {
        alert(current);
    },
    labels: {
        finish: 'Sign Up <i class="fa fa-chevron-right"></i>',
        next: 'Next <i class="fa fa-chevron-right"></i>',
        previous: '<i class="fa fa-chevron-left"></i> Previous'
    }
});

HTML:

<h3><?= $lang_wizard_account; ?></h3>
<fieldset>
    <legend><?= $lang_text_your_details; ?></legend>
    <div class="form-group">
        <label class="control-label col-sm-3" for="username"><b class="required">*</b> <?= $lang_entry_username; ?></label>
        <div class="col-sm-8">
            <input type="text" name="username" value="<?= $username; ?>" class="form-control" placeholder="<?= $lang_entry_username; ?>" autofocus id="username" required>
            <?php if ($error_username) { ?>
            <span class="help-block error"><?= $error_username; ?></span>
            <?php } ?>
        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-sm-3" for="firstname"><b class="required">*</b> <?= $lang_entry_firstname; ?></label>
        <div class="col-sm-8">
            <input type="text" name="firstname" value="<?= $firstname; ?>" class="form-control" placeholder="<?= $lang_entry_firstname; ?>" id="firstname" required>
            <?php if ($error_firstname) { ?>
            <span class="help-block error"><?= $error_firstname; ?></span>
            <?php } ?>
        </div>
    </div>
    .... 
</fieldset>

好吧,非常丑陋的 hack,但它确实按预期工作:

$("#register-form").steps({
    headerTag: "h3",
    bodyTag: "fieldset",
    autoFocus: true,
    onInit: function (event, current) {
        $('.actions > ul > li:first-child').attr('style', 'display:none');
    },
    onStepChanged: function (event, current, next) {
        if (current > 0) {
            $('.actions > ul > li:first-child').attr('style', '');
        } else {
            $('.actions > ul > li:first-child').attr('style', 'display:none');
        }
    },
    labels: {
        finish: 'Sign Up <i class="fa fa-chevron-right"></i>',
        next: 'Next <i class="fa fa-chevron-right"></i>',
        previous: '<i class="fa fa-chevron-left"></i> Previous'
    }
});

感谢whitebox!

这具有相同的效果,但不那么骇人听闻:

.wizard > .actions > ul > li.disabled {
  display: none;
}

这是一个很好的解决方案,使用 jQuery:

$("a[href$='next']").hide();
$("a[href$='previous']").hide();

此解决方案允许您调用 .click() 函数转到下一个或上一个,如下所示:

$("a[href$='next']").click();

$("a[href$='previous']").click();

以前的解决方案对我来说不太管用,但这个确实管用:

.wizard > .actions > ul > li.disabled > a {
  background: white;
}