简体   繁体   English

introJs() API 在附加到 jquery 模式对话框内的元素时不起作用

[英]introJs() API is not working when attached to an element inside a jquery modal dialog box

I am trying to show an Intro.js tour on an element which is inside a <table> .我正在尝试在<table>内的元素上展示 Intro.js 导览。 The <table> is inside a jquery UI dialog box <table>位于jquery UI 对话框内

I am populating the table rows in my JavaScript:我正在填充我的 JavaScript 中的表行:

while (i != 10) {
  var row = t1.insertRow(t1.rows.length);
  var cell = row.insertCell(0);
  var cell1 = row.insertCell(1);
  
  cell.innerText = "some text";

  var input = document.createElement("select");
  
  input.className = "abc";
  
  for (var j = 0; j < insts.length; j++) {
    var option = document.createElement("option");
    
    option.value = insts[j];
    option.text = insts[j];
    input.appendChild(option);
  }
  
  cell2.appendChild(input);
}

After that, I am displaying my dialog box, which opens a modal dialog box:之后,我将显示我的对话框,它会打开一个模态对话框:

$(function() {
  $("#dialog").dialog({
    modal: true,
    autoOpen: false,
    width: "auto",
    height: "auto",
    show: {
      effect: "slide",
      duration: 1000
    },
    hide: {
      effect: "fold",
      duration: 1000
    }
  });
  $("#dialog").dialog("open");
});

Now, when there's any change in the <select> element, I want to trigger an Intro.js tour like this:现在,当<select>元素发生任何变化时,我想像这样触发 Intro.js 之旅:

document.addEventListener("change", function(e) {
  if (e.target.className == "abc") {
    introJs().setOption("dontShowAgain", true).start();
  }
})

But the Intro.js tour never starts, even when I change the values of any of the <select> elements.但是 Intro.js 之旅永远不会开始,即使我更改了任何<select>元素的值也是如此。 When I attach the introJS listener to the main window, then it works.当我将introJS侦听器附加到主 window 时,它就可以工作了。 But when I attach it to any element inside the modal dialog box it doesn't work.但是当我将它附加到模式对话框内的任何元素时它不起作用。 Why is that?这是为什么? How do I fix this?我该如何解决?

EDIT: The introJS() tour should show inside this modal dialog box (pointed by the red arrow)编辑: introJS()游览应该显示在此modal dialog box内(由红色箭头指向)

screenshot截屏

Without seeing a debugging session directly in the browser, I'd start with making sure a event listener is assigned to each select object. Since you are in a loop, there will be multiple.在没有直接在浏览器中看到调试 session 的情况下,我首先要确保为每个 select object 分配了一个事件侦听器。由于您处于循环中,因此会有多个。

// in while loop
var input = document.createElement("select");
input.setAttribute("id", "selector_"+i)
// still in loop
input.addEventListener("change", function() {
        // do stuff
});
i++;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM