我有一个span元素,当单击/触摸该元素时,应该会在jQuery中触发某些操作。

<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侦听器的其他元素工作得很好。控制台上也没有显示错误。顺便说一句,一切似乎都在桌面上正常工作。
我知道这个问题以前被反复问过,但在这个例子中,我似乎找不到解决办法。任何关于如何解决这个问题的洞察力都是值得赞赏的。
发布于 2015-01-18 21:00:22
我能够通过添加
display:inline-block敬.locationElementBtn。在移动环境中,对于内联 (span)元素,链接命中空间似乎不太明显,因此jQuery事件不会被触发。它可能与包含字体图标的元素有关。
感谢t.niese的提示!
https://stackoverflow.com/questions/28014139
复制相似问题