javascript - 为什么我的touchstart事件无效?
伊谢尔伦
伊谢尔伦 2017-04-10 16:47:29
0
2
310
$(document).ready(function() { $(".mask").hide(); var maskshow = function() { $(this).children(".mask").toggle(); } $('.pic-show').on('touchstart', maskshow); });

希望达到的目的是在移动端通过触摸使我的遮罩层mask显示或者隐藏(用的toggle)
但是无效
换了一种写法还是不行

$(document).ready(function() { $(".mask").hide(); $(function(){ $(".image").addEventListener("touchmove", _touch, false); }) function _touch(event){ $(this).children(".mask").toggle(); } });

用click就正常

$(document).ready(function(){ $(".mask").hide(); $(".image").click(function(){ $(this).children(".mask").toggle(); }); });

请问是什么原因 - -。
新人,刚接触touchstart,百度半天没找到原因就来问了,求不吝赐教

伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

reply all (2)
伊谢尔伦
$(document).ready(function() { $(".mask").hide(); var maskshow = function() { $(this).children(".mask").toggle(); //$(this)指向调用maskshow的 $('.pic-show') jquery对象 //你的.mask不是$('.pic-show')的children吧? } $('.pic-show').on('touchstart', maskshow); });
    黄舟

    将touchstart换成touchend就可以了。

      Latest Downloads
      More>
      Web Effects
      Website Source Code
      Website Materials
      Front End Template
      About us Disclaimer Sitemap
      php.cn:Public welfare online PHP training,Help PHP learners grow quickly!