簡體   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