动态创建jQuery步骤的步骤

时间:2014-02-03 02:01:43

标签: javascript jquery html dynamically-generated jquery-steps

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

这是我的代码:

<!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>

运行此页面时,网页上显示的所有内容都是“下一页”和“上一页”,但根本没有步骤。

我得到的控制台错误是:

  

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

我可以帮忙解决这个问题吗?

提前致谢

2 个答案:

答案 0 :(得分:4)

您似乎需要在调用$('#wizard').steps();

时添加一些内容

查看basic example

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

尝试将您的更改为

$(function () {

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

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

});

答案 1 :(得分:1)

更新代码

 $(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"
        });                 
    });