繁体   English   中英

忽略尝试取消touchstart的尝试:fastclick警告

[英]Ignored attempt to cancel a touchstart : fastclick warning

我有第一个弹出窗口,另一个弹出窗口用来选择几个字段。 为了显示第二个弹出窗口,这是我正在尝试的代码:

$("#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个。 只有前1个可点击。 第二个弹出窗口的快照。

在此处输入图片说明

我阅读了讨论该主题的所有博客。 但是没有任何解决方案对我有用。 似乎有一些极端情况。

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

$("#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"运行each() 1次问题。

因此,实际的问题是each()仅运行1次,这就是为什么您的第一个元素(即Ready click事件)可以正常工作的原因,而不是其他因素。

暂无
暂无

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

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