忽略取消触摸启动的尝试:快速点击警告

Ignored attempt to cancel a touchstart : fastclick warning

我有第一个弹出窗口,另一个弹出窗口出现在 select 几个字段上。 要显示第二个弹出窗口,这是我正在尝试的代码:

$("#select1").click(function(e) {
  e.stopPropagation();
  //$('#sellerModal').hide();
  var tmplData = {
    string:['Ready','2-3 Days','4-5 Days','1 Week','10+ Days']
  };
  $("#countTypePopupTemplate").tmpl(tmplData).appendTo(".maindiv");
  that.closePopup();
  $("#count_div").each(function() {
    $("#count_div").click(function(evt) {
      evt.stopPropagation();
      $("#select1").text($(this).text());
      $("#myCounttype").remove();
    });
  });
});

这是 HTML 模板:

<script id="countTypePopupTemplate" type="text/x-jquery-tmpl">
  <div id="myCounttype" class="popup1 layer-2">
    <div class="popup5">
      {{each string}}
      <div id="count_div" class="popup4 bottom-border">${$value}</div>
      {{/each}}
    </div>
  </div>
</script>

我收到警告:

Ignored attempt to cancel a touchstart event with cancelable=false, for example, because scrolling is in progress and cannot be interrupted. fastclick.js

我无法在第二个弹出窗口中点击 5 个元素中的 4 个。只有第一个是可点击的。 第二个弹出窗口的快照。

我阅读了所有讨论该主题的博客。但是没有任何解决方案适合我。看起来有一些极端情况。

您的每个函数都指向 id,这使您无法单击其他按钮。您应该使用 class 来识别按钮。

$("#select1").click(function(e) {
  e.stopPropagation();
  //$('#sellerModal').hide();
  var tmplData = {
    string:['Ready','2-3 Days','4-5 Days','1 Week','10+ Days']
  };
  $("#countTypePopupTemplate").tmpl(tmplData).appendTo(".maindiv");
  that.closePopup();
  $(".pop_btns").each(function() {
    $(this).click(function(evt) {
      evt.stopPropagation();
      $("#select1").text($(this).text());
      $("#myCounttype").remove();
    });
  });
});

HTML 模板:

<script id="countTypePopupTemplate" type="text/x-jquery-tmpl">
  <div id="myCounttype" class="popup1 layer-2">
    <div class="popup5">
      {{each string}}
      <div id="count_div" class="popup4 bottom-border pop_btns">${$value}</div>
      {{/each}}
    </div>
  </div>
</script>

尝试在 $("#count_div").each(function() { $("#count_div").click(function(evt) { 之前使用一些父选择器 像这样$(".parent_class #count_div").each(function() { $(".parent_class #count_div").click(function(evt) {

这将为 "#count_div".

解决 1 次 运行 each()

所以实际问题是 each() 只 运行 一次,这就是为什么你的第一个元素 Ready click 事件起作用,而不是其他。