【问题标题】:How do I get the current step in jQuery steps wizard?如何获取 jQuery 步骤向导中的当前步骤?
【发布时间】:2015-04-09 15:38:23
【问题描述】:

我正在寻找一种方法来获取我的jQuery Steps wizard 中的当前步骤。如果当前步骤是第 1 步,我想执行一个操作。

【问题讨论】:

  • 不知道这怎么不清楚,提供答案的人似乎也觉得很清楚。

标签: jquery jquery-steps


【解决方案1】:

这会将当前步骤索引作为整数返回。

$("#wizard").steps("getCurrentIndex");

这个步骤索引是从零开始的。

因此,要在第一步执行操作(我假设您所说的“步骤 1”),您应该这样做:

if ( $("#wizard").steps("getCurrentIndex") == 0 ) {
    perform_action();
}

参考:https://github.com/rstaib/jquery-steps/wiki/Methods

【讨论】:

    【解决方案2】:

    onStepChanging and onStepChanged 事件有currentIndex 参数。您可以将您的操作放在函数中以处理任何这些事件。

    【讨论】:

      【解决方案3】:

      答案可以在下载的示例代码中找到:

      https://github.com/rstaib/jquery-steps

      这是我发现有用的 sn-p:

                  // 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 );
      

      【讨论】:

      • 没有检测到事件,有什么想法吗?
      【解决方案4】:

      如果当前步骤为 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');
      

      【讨论】:

        【解决方案5】:
        $('.selected').prop('rel')
        

        对于 SmartWizard 3.3.1,所选步骤始终具有 class='selected'。因此,使用该类,您可以根据自己的需要进行操作。

        【讨论】:

          【解决方案6】:
          $("#wizard").smartWizard("currentStep");
          

          对于旧版本。

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2018-03-28
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多