jQuery点击/触摸事件不会在移动中触发(内联元素)

时间:2015-01-18 19:54:57

标签: javascript jquery html mobile google-chrome-devtools

我有一个span元素,当点击/触摸时应触发jQuery中的某些操作。

enter image description here

HTML

<span id="" class="dwr_icon_location locationElementBtn"></span>

的jQuery

$(document).ready(function(){
  // Location Button
  $(document).on("click touchstart",".locationElementBtn", function(){
      $(".locationBtn").toggleClass("active");

      // Displaying location window in the proper bar
      var locationBtn   = $(this).parent(".locationBtn");
      var locationStngs = $("#locationStngs");

      // if locationStngs doesn't exist in the current bar
      if(!locationBtn.children("#locationStngs").length){
        locationBtn.append(locationStngs);
      }
  });
});

问题是该事件永远不会在移动中被解雇,尽管附加了jQuery监听器的其他元素工作得很好。控制台上也没有显示错误。顺便说一下,一切似乎都在桌面上工作。

我知道此问题之前已经被重复询问,但在这种情况下我似乎找不到解决方案。任何有关如何解决此问题的见解表示赞赏。

1 个答案:

答案 0 :(得分:1)

我能够通过添加

解决问题
display:inline-block

.locationElementBtn。对于移动设备上的内联(span)元素,链接命中空间似乎并不那么明显,因此jQuery事件不会被触发。它可能与包含字体图标的元素有关。

感谢t.niese提示!