【问题标题】:Bootstrap Tour won't startBootstrap Tour 无法开始
【发布时间】:2014-06-27 11:20:32
【问题描述】:

我在我的网站和 this fiddle 中设置了以下非常简单的演示。它与 the official demo 几乎相同。在这两种情况下,我都没有参观。我错过了什么?

<link rel="stylesheet" type="text/css" href="//cdnjs.cloudflare.com/ajax/libs/bootstrap-tour/0.8.1/css/bootstrap-tour.min.css"> 
<link rel="stylesheet" type="text/css" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">

<script type='text/javascript' src='http://code.jquery.com/jquery-git.js'></script>
<script type='text/javascript' src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
<script type='text/javascript' src="//cdnjs.cloudflare.com/ajax/libs/bootstrap-tour/0.8.1/js/bootstrap-tour.min.js"></script>

<button class="btn" id="tour-go">Start the tour!</button>

<form>
    <input id="one" value="one" />
    <input id="two" value="two" />
    <input id="three" value="three" />
</form>

$(function () {
    var tour = new Tour({
        steps: [{
            element: "#one",
            title: "Title of my step",
            content: "Content of my step"
        }, {
            element: "#two",
            title: "Title of my step",
            content: "Content of my step"
        }, {
            element: "#three",
            title: "Title of my step",
            content: "Content of my step"
        }]
    });

    // Initialize the tour
    tour.init();

    $('#tour-go').click(function () {
        // Start the tour
        tour.start();
    });
});

【问题讨论】:

  • 我也尝试在本地加载 Tour v0.9.1,使用官方演示中的 JS 和 HTML。仍然没有快乐。

标签: jquery bootstrap-tour


【解决方案1】:

我尝试了上述所有建议的解决方案,但仍然无法使其工作,所以我在网上找到了一篇文章,指出现有引导用户应该使用@ 987654321@。相反,他们应该使用boostrap-tour-min.js

另外,请确认您使用的是适当版本的引导程序。 “弹出窗口”在我的情况下没有显示我切换到

<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>

【讨论】:

    【解决方案2】:

    您使用的是 bootstrap-tour v0.8.1,因此您的代码不正确,正确的是:

    var tour = new Tour() ;
    
    tour.addSteps([{
        element: "#one",
        title: "Title of my step",
        content: "Content of my step"
    }, {
        element: "#two",
        title: "Title of my step",
        content: "Content of my step"
    }, {
        element: "#three",
        title: "Title of my step",
        content: "Content of my step"
    }]) ;
    

    这个小提琴正在工作:http://jsfiddle.net/9LcQx/

    【讨论】:

    • 我从这个场景中学到了两件事:首先,你的语法确实有效。其次,Tour 中有一个错误,在某些情况下需要使用restart() 而不是start()。这是 at 结合了两个修复的小提琴:jsfiddle.net/isherwood/tN4Uq/2 感谢您的帮助。
    • @isherwood 我认为你所看到的错误是引导程序的一个功能,它使用本地存储在重新加载页面时保持当前步骤。如果要禁用此功能,则必须在构造函数中将storage 选项设置为false
    • 我认为你是对的。我指的是这个错误:github.com/sorich87/bootstrap-tour/issues/212 但我猜它已经被纠正了。我不知道 Tour 内置的状态存储功能。谢谢。
    【解决方案3】:

    your fiddle的这个替换你的js:

    $(function () {
        var tour = new Tour();
        tour.addStep({
          element: "#one",
          title: "Step 1",
          content: "Content for step 1"
        });
    
        tour.addStep({
          element: "#one",
          title: "Step 2",
          content: "Content for step 2"
        });
    
        tour.addStep({
          element: "#three",
          title: "Step 3",
          content: "Content for step 3"
        });
        // Initialize the tour
        tour.init();
    
        $('#tour-go').click(function () {
            // Start the tour
            tour.start();
        });
    });
    

    【讨论】:

    • 与其他答案不同,这对我有用。干得好。
    • 谢谢。不同的语法是我的问题的一部分。另一部分是 Tour 中的一个错误,要求我使用 restart() 而不是 start() 进行后续点击。 jsfiddle.net/isherwood/tN4Uq/2
    【解决方案4】:

    你的错误是使用 steps。但正确的是您必须使用 tour.addStep 来完成此操作。

    检查这个Demo js Fiddle

    jQuery

    var tour = new Tour();
    
    tour.addStep({
            element: "#one",
            title: "Title of my step",
            content: "Content of my step"
        });
    tour.addStep({
            element: "#two",
            title: "Title of my step",
            content: "Content of my step"
    });
    tour.addStep({
            element: "#three",
            title: "Title of my step",
            content: "Content of my step"
    });
    
    // Initialize the tour
    tour.init();
    
    $('#tour-go').click(function () {
        // Start the tour
        console.log("Click");
        tour.start();
    });
    

    【讨论】:

    • 那个小提琴看起来像我开始使用的那个,但它使用了我认为是旧的语法并链接到旧版本的外部文件(Bootstrap 2)。无论如何,它不起作用。
    • 原来你的答案是正确的。如果您想编辑答案,我会投票。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多