jQuery手机(点击事件) [英] jQuery mobile (click event)

查看:257
本文介绍了jQuery手机(点击事件)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发智能手机混合应用程序。

I'm developing smartphone hybrid applications.

我试图隐藏/显示一个< div> slideDown / slideUp

I'm trying to hide/show a <div> with slideDown/slideUp.

当我点击按钮,菜单< div> 应该隐藏/显示上下文的依赖。一切都在我的电脑上运行正常,但在手机上完全不起作用,没有任何反应。

When I click on the button, the menu <div> is supposed to hide/show depend of the context. Everything is working well on my computer but it just doesn't work at all on my mobile, nothing happens.

这是我的HTML代码

<a class="btnMenuDyn" data-role="button">Masquer le menu</a>

这里我的jQuery手机代码:

and here my jQuery mobile code:

$(document).bind('pageinit', function(e){


// définition des variables
var btnMenuDyn = $('a.btnMenuDyn'),
    menuDyn = $('div.menuDyn');

$(btnMenuDyn).bind('click', function(){


    // condition pour afficher ou non le menu
    if ($(menuDyn).hasClass("menuDynHide"))
    {
        $(menuDyn).slideDown().removeClass("menuDynHide");
    }
    else{
        $(menuDyn).slideUp().addClass("menuDynHide");
    }

});
});


推荐答案

这个问题是手机不支持点击他们使用touchstart如果你还想在电脑上测试,可以跟踪运动。

this problem is mobiles do not support click they use touchstart and touchend so can track movement if you still want to test on computers you can do this

$(btnMenuDyn).bind('touchstart mousedown', function(event){
    event.preventDefault();
    if ($(menuDyn).hasClass("menuDynHide"))
    {
        $(menuDyn).slideDown().removeClass("menuDynHide");
    }
    else{
        $(menuDyn).slideUp().addClass("menuDynHide");
    }

});

另一个同样答案的问题 jquery touchstart在浏览器

another question with same answer jquery touchstart in browser

更多信息可以在 http://backtothecode.blogspot.com/2009/10/javascript-touch-and-gesture-events .html

这篇关于jQuery手机(点击事件)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆