首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >智能向导-只重置第一个实例的倍数

问智能向导-只重置第一个实例的倍数
EN

Stack Overflow用户
提问于 2020-06-19 10:50:24
回答 1查看 531关注 0票数 1

我有一个具有多个聪明巫师的表单,每个表单的UID都是递增的。当单击窗体返回或重置按钮(从向导外部)时,我希望重新启动向导到步骤1。步骤重置仅在智能向导的第一个实例上进行。我试着更新我的JS,以包含所有包含“智能手表蜥蜴”的is,但它仍然只针对第一个is。

在最新的v5 多重演示上,当在向导上推进步骤并在第二个向导上单击cancel时,可以查看相同/类似的行为,这只会在第一个向导上触发重置。

我是否遗漏了智能向导代码中的“重置”键上的事件处理方式和位置(请参阅源代码链接以获得参考)?我需要从这一点上的指导,所以任何洞察力都是值得赞赏的.

jQuery / JS文件

代码语言:javascript
复制
//FUNCTIONS FOR THE FORM BUTTONS
$('#back-button').on('click', function(event) {
    $('[id*="smartwizard"]').smartWizard('reset');
});

$('#reset-button').on('click', function(event) { // Reset form to initial state
    $('[id*="smartwizard"]').smartWizard('reset');
});

SmartWizard

代码语言:javascript
复制
      key: "reset",
  value: function reset() {
    // Reset all
    this._setURLHash('#');

    this._initOptions();

    this._initLoad();
  }

HTML文件

代码语言:javascript
复制
//FORM SNIPPET
                                <ul>
                                    <li class="process" id="process1">
                                        <div id="smartwizard">
                                            <ul class="nav">
                                                <li class="nav-item">
                                                    <a class="nav-link" href="#step-1">
                                                        <strong>Step 1</strong> <h4>Introduction</h4>
                                                    </a>
                                                </li>
                                            </ul>

                                            <div class="tab-content">
                                                <div id="step-1" class="tab-pane" role="tabpanel" aria-labelledby="step-1">
                                                    <h3>Step 1 Content</h3>
                                                    Lorem Ipsum is simply dummy text of the printing and typesetting industry.
                                                </div>
                                                <div id="step-2" class="tab-pane" role="tabpanel" aria-labelledby="step-2">
                                                    <h3>Step 2 Content</h3>
                                                    Lorem Ipsum is simply dummy text of the printing and typesetting industry.
                                                </div>
                                            </div>
                                        </div>
                                    </li>
                                </ul>


                                <ul>
                                    <li class="process" id="process2">
                                        <div id="smartwizard2">
                                            <ul class="nav">
                                                <li class="nav-item">
                                                    <a class="nav-link" href="#step-1">
                                                        <strong>Step 1</strong> <h4>Introduction</h4>
                                                    </a>
                                                </li>
                                            </ul>

                                            <div class="tab-content">
                                                <div id="step-1" class="tab-pane" role="tabpanel" aria-labelledby="step-1">
                                                    <h3>Step 1 Content</h3>
                                                    Lorem Ipsum is simply dummy text of the printing and typesetting industry.
                                                </div>
                                                <div id="step-2" class="tab-pane" role="tabpanel" aria-labelledby="step-2">
                                                    <h3>Step 2 Content</h3>
                                                    Lorem Ipsum is simply dummy text of the printing and typesetting industry.
                                                </div>
                                            </div>
                                        </div>
                                    </li>
                                </ul>
                            </li>
                        </ul>
                    </li>
                </ul>
            </li>
        </ul>
    </div>
    <div class="buttons">
        <button id="back-button" type="button">BACK</button>
        <button id="reset-button" type="reset">RESET</button>
    </div>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-06-24 02:05:45

幸运的是,我发现了一些关于如何使用.each()和ID数组迭代所有智能向导的灵感。

我仍然认为,为了简单起见,代码可以重构,以包含包含“智能手表蜥蜴”的所有in,但这解决了两个外部按钮的问题,而且随着更多智能向导被添加到页面中,我只需要在一个地方维护数组值。

代码语言:javascript
复制
var wizard = ["smartwizard", "smartwizard2"];

$('#back-button').on('click', function(event) { // Undo last selection and reset steps
    $.each(wizard, function(i, val) {
        $("#" + val).smartWizard('reset');
    });
});


$('#reset-button').on('click', function(event) { // Reset steps to initial state
    $.each(wizard, function( i, val ) {
        $("#" + val).smartWizard('reset');
    });
});
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62468632

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档