我正在寻找一种在我的jQuery Steps 向导中获取当前步骤的方法。如果当前步骤是第 1 步,我想执行一个操作。
问问题
16449 次
6 回答
7
这会将当前步长索引作为整数返回。
$("#wizard").steps("getCurrentIndex");
这个步长索引是从零开始的。
因此,要在第一步执行操作(我假设您所说的“步骤 1”),您将执行以下操作:
if ( $("#wizard").steps("getCurrentIndex") == 0 ) {
perform_action();
}
于 2015-08-12T16:25:52.363 回答
2
有onStepChanging
和onStepChanged
有currentIndex
参数的事件。您可以将您的操作放在函数中以处理任何这些事件。
于 2015-02-10T13:49:48.057 回答
1
答案可以在下载的示例代码中找到:
https://github.com/rstaib/jquery-steps
这是我发现有用的片段:
// Example 1: Basic wizard with validation
$( "#example-1" ).wizard({
submit: ".submit",
beforeForward: function( event, state ) {
if ( state.stepIndex === 1 ) {
$("#name").text($("[name=name]").val());
} else if ( state.stepIndex === 2 ) {
$("#gender").text($("[name=gender]").val());
}
return $( this ).wizard( "form" ).valid();
}
}).wizard( "form" ).submit(function( event ) {
event.preventDefault();
alert( "Form submitted!" );
}).validate( validate );
于 2018-08-16T17:04:58.637 回答
0
如果当前步骤为 3,我使用此代码禁用第 1 步和第 2 步,将此代码添加到 jquery.steps.js
$.fn.steps.done = function () {
var wizard = this,
options = getOptions(this),
state = getState(this);
if(state.currentIndex == 2){
for (i = 0; i < 2; i++) {
var stepAnchor = getStepAnchor(wizard, i);
stepAnchor.parent().removeClass("done")._enableAria(false);
}
}
};
并将其添加到您的 html
$("#wizard").steps('done');
于 2015-02-16T10:08:06.563 回答
0
$("#wizard").smartWizard("currentStep");
对于旧版本。
于 2019-08-21T22:47:25.577 回答
0
$('.selected').prop('rel')
对于 SmartWizard 3.3.1,所选步骤始终具有class='selected'
. 因此,使用该类,您可以根据您想要做的操作进行操作。
于 2019-05-22T13:24:51.187 回答