jquery - 禁用按钮,直到使用 jQuery Steps 采取特定操作?

标签 jquery jquery-steps

我遇到了 jQuery Steps 的问题插入。在采取特定操作之前,必须禁用下一步按钮,如果数据经过正确验证,则应启用该按钮。

所以问题是:如何将下一步按钮设置为默认禁用,以及是否有可用的方法以编程方式启用或禁用下一步按钮?

这是我当前的代码:

HTML:

<div id="steps">
    <h3>Write question</h3>
    <section>
        <input type="text" id="question" placeholder="Question goes here">
        <button id="save">Save and do something else</button>
    </section>

    <h3>Preview</h3>
    <section>
        <p id="preview"></p>
    </section>

    <h3>Done</h3>
    <section>
        <p>Congratulations text goes here</p>
    </section>
</div>

jQuery:

//start
$(function(){
    $('#steps').steps({
        headerTag: "h3",
        bodyTag: "section",
        transitionEffect: "slideLeft",
        stepsOrientation: "vertical"
    });

    $('#save').click(function(){
        $('#preview').html($('#question').val());

        //do something else (ajax wise, etc)
        if(true) {
            //enable NEXT button here...
        }
    });
});

最佳答案

这个问题很久以前就被问过,但我觉得这可以帮助别人。

jQuery Steps 插件,可以监听 onStepChanging 事件: 除非设置了标志,否则返回 false。

$(function() {
    $("#steps").steps({

        //Events
        onStepChanging: function (event, currentIndex, newIndex){
            if(currentIndex==2 && flag==false){
                return false;
            }
            else{
                return true; 
            }     
        },
    });
});

For more information on the jQuery plugin

关于jquery - 禁用按钮,直到使用 jQuery Steps 采取特定操作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34795287/

相关文章:

javascript - jQuery Steps 新步骤被添加到新行

javascript - jQuery父选择器查找步骤

jQuery .show() 一个 flexbox

javascript - 此 Accordion 在同一页面上的多个实例

javascript - Owl Carousel 2 - 隐藏自定义导航(如果有 1 项)

jquery-steps - icheck 无法在 jquery-steps 向导中工作

javascript - jquery-steps:如何防止页面滚动到顶部?

Jquery步骤->按钮单击->转到步骤

jquery - 在 jquery 中动态添加文本框

javascript - 如何让 canvas 100% 适配屏幕?