Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 使用ajax调用在移动设备上滚动页面时防止touchstart_Jquery_Ajax_Touchstart - Fatal编程技术网

Jquery 使用ajax调用在移动设备上滚动页面时防止touchstart

Jquery 使用ajax调用在移动设备上滚动页面时防止touchstart,jquery,ajax,touchstart,Jquery,Ajax,Touchstart,通常情况下,代码如下: var touchmoved; $('button').on('touchend', function(e){ if(touchmoved != true){ // you're on button click action } }).on('touchmove', function(e){ touchmoved = true; }).on('touchstart', function(){ touchmoved = fal

通常情况下,代码如下:

var touchmoved;
$('button').on('touchend', function(e){
    if(touchmoved != true){
        // you're on button click action
    }
}).on('touchmove', function(e){
    touchmoved = true;
}).on('touchstart', function(){
    touchmoved = false;
});
但是,这段代码似乎不适用于动态生成的ajax元素

为此,我有以下代码:

var touchmoved;
$(document).on('click touchend', '.menu', function(){
    if(touchmoved != true){
        // you're on button click action
    }
}).on('touchmove', '.menu', function(e){
    touchmoved = true;
}).on('touchstart', '.menu', function(){
    touchmoved = false;
});
现在它适用于web界面,但似乎不适用于移动界面


是否有一项工作可以让我动态调用ajax并使其正常工作?

结果证明我最初发布的代码是正确的答案

我正在使用一个名为nicesroll的第三方脚本,它在我下载的版本中有一些bug

因此,对于未来几代人来说,防止动态生成元素的touchstart的方法(目前)是:

var touchmoved;
$(document).on('click touchend', '.menu', function(){
    if(touchmoved != true){
        // your click action here!!!
    }
}).on('touchmove', '.menu', function(e){
    touchmoved = true;
}).on('touchstart', '.menu', function(){
    touchmoved = false;
});

任何人我真的没有找到答案。我会继续找的。