0

我正在使用Joyride 插件进行导游。我需要获取在函数ol中启动兜风的旅游 ID(标签 ID) 。postRideCallback这个函数只有indexandcurrent_tip作为参数,我不知道如何获取 ID handlePostRideCall,我研究了这个库,没有任何效果。

HTML:

/* Each tip is set within this <ol>. */
/* This creates the order the tips are displayed */
<ol id="joyRideTipContent">
  /* data-id needs to be the same as the parent it will attach to */
  <li data-id="newHeader">Tip content...</li>

  /* This tip will be display as a modal */
  <li>Tip content...</li>

  /* using 'data-button' lets you have custom button text */
  <li data-class="parent-element-class" data-options="tipLocation:top;tipAnimation:fade" data-button="Second Button">Content...</li>

  /* you can put a class for custom styling */
  <li data-id="parentElementID" class="custom-class">Content...</li>
</ol>

JS:

<script>
    $(window).load(function() {
        $('#joyRideTipContent').joyride({
            autoStart : true,
            postStepCallback : handlePostRideCall,
            modal:true,
            expose: true
        });
    });

    function handlePostRideCall(index, tip){
        // get ol ID here
    }
</script>
4

1 回答 1

1

创建变量

var joyride_parent_id;

然后在tip_template : function (opts) {函数中就可以得到父节点的id,ol并保存在我们上面定义的变量中

 joyride_parent_id = $(opts.li).parent().attr('id');

现在我们需要将它传递给当关闭事件触发时被调用的回调函数

end : function () {
        .......
        if (settings.$li) {
          settings.postStepCallback(settings.$li.index(), settings.$current_tip);
          settings.postRideCallback(settings.$li.index(), settings.$current_tip, joyride_parent_id);
        }
        $('.joyride-modal-bg').hide();
      },
于 2013-12-03T16:22:32.097 回答