javascript 为 jQuery Steps 动态创建步骤

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21518707/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 21:04:49  来源:igfitidea点击:

Dynamically create steps for jQuery Steps

javascriptjqueryhtmldynamically-generatedjquery-steps

提问by user2985419

I am having some trouble dynamically creating some steps using the jQuery Step Wizard plugin.

我在使用 jQuery Step Wizard 插件动态创建一些步骤时遇到了一些麻烦。

Here is my code:

这是我的代码:

<!DOCTYPE html>
<html>
    <head>
        <title>Demo</title>
        <meta charset="utf-8">

        <script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
        <script>window.jQuery || document.write('<script src="js/jquery-1.10.2.min.js"><\/script>')</script>
        <script src="http://code.jquery.com/mobile/1.4.0/jquery.mobile-1.4.0.min.js" type="text/javascript"></script>
        <script>$.mobile || document.write('<script src="js/jquery.mobile-1.4.0.min.js"><\/script>')</script>

        <script src="scripts/libs/modernizr-2.6.2-respond-1.1.0.min.js"></script>
        <script src="scripts/libs/jquery.steps-1.0.4.js"></script>
        <script src="scripts/libs/jquery.validate-1.11.1.min.js"></script>  

    </head>
    <body>
        <script>

            $(document).ready(function () {
                $("#wizard").steps();

                var wizard = $("#wizard").steps();
                wizard.steps("add", {
                    title: "HTML code", 
                    content: "This is a test"
                });
                wizard.steps("add", {
                    title: "HTML code2", 
                    content: "This is a test2"
                });                 
            });

        </script>
        <div id="wizard"></div>
    </body>
</html>

When this page is run, all that is shown on the web page is a "next" and a "previous", yet no steps at all.

运行此页面时,网页上显示的只是“下一个”和“上一个”,但根本没有任何步骤。

The console error I am getting is this:

我得到的控制台错误是这样的:

SCRIPT5022: One or more corresponding step titles are missing. jquery.steps-1.0.4.js, line 1252 character 5

SCRIPT5022:缺少一个或多个相应的步骤标题。jquery.steps-1.0.4.js,第 1252 行字符 5

Can I have some help to get this working?

我可以得到一些帮助来完成这项工作吗?

Thanks in advance

提前致谢

回答by reergymerej

It looks like you need to include something in your call to $('#wizard').steps();

看起来您需要在调用中包含一些内容 $('#wizard').steps();

Look at the basic example.

看一下基本的例子

$("#wizard").steps("add", {
  title: "Step Title",
  contentMode: "async",
  contentUrl: "data.xml"
});

Try changing yours to

尝试将您的更改为

$(function () {

  $('#wizard').steps("add", {
    title: "HTML code", 
    content: "This is a test"
  })

  .steps("add", {
    title: "HTML code2", 
    content: "This is a test2"
  });                 

});

回答by P.Sethuraman

Updated Code

更新代码

 $(document).ready(function () {
        ***$("#wizard").steps();***    //remove this line from your code

        var wizard = $("#wizard").steps();
        wizard.steps("add", {
            title: "HTML code", 
            content: "This is a test"
        });
        wizard.steps("add", {
            title: "HTML code2", 
            content: "This is a test2"
        });                 
    });