我有一个具有多个聪明巫师的表单,每个表单的UID都是递增的。当单击窗体返回或重置按钮(从向导外部)时,我希望重新启动向导到步骤1。步骤重置仅在智能向导的第一个实例上进行。我试着更新我的JS,以包含所有包含“智能手表蜥蜴”的is,但它仍然只针对第一个is。
在最新的v5 多重演示上,当在向导上推进步骤并在第二个向导上单击cancel时,可以查看相同/类似的行为,这只会在第一个向导上触发重置。
我是否遗漏了智能向导代码中的“重置”键上的事件处理方式和位置(请参阅源代码链接以获得参考)?我需要从这一点上的指导,所以任何洞察力都是值得赞赏的.
jQuery / JS文件
//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
key: "reset",
value: function reset() {
// Reset all
this._setURLHash('#');
this._initOptions();
this._initLoad();
}HTML文件
//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>发布于 2020-06-24 02:05:45
幸运的是,我发现了一些关于如何使用.each()和ID数组迭代所有智能向导的灵感。
我仍然认为,为了简单起见,代码可以重构,以包含包含“智能手表蜥蜴”的所有in,但这解决了两个外部按钮的问题,而且随着更多智能向导被添加到页面中,我只需要在一个地方维护数组值。
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');
});
});https://stackoverflow.com/questions/62468632
复制相似问题