单击按钮在iDevices上不起作用

时间:2013-03-07 14:21:48

标签: jquery html html5 mobile-safari

我有这个向下滑动的标题,按下它时向下滑动。

样本: http://jsfiddle.net/ygAV2/2/

$(document).on("click", 'h1', function() {
    if (!$(this).parent().hasClass('header-down')) {
        $(this).parent().stop().animate({
            height: '100px'
        }, {
            queue: false,
            duration: 600,
            easing: 'linear'
        }).addClass('header-down');
    } else {
        $(this).parent().stop().animate({
            height: '30px'
        }, {
            queue: false,
            duration: 600,
            easing: 'linear'
        }).removeClass('header-down');
    }
});



$(document).click(function () {
    if ($(".box_header").hasClass('header-down')) {
        $(".box_header").stop().animate({
            height: '30px'
        }, {
            queue: false,
            duration: 600,
            easing: 'linear'
        }).removeClass('header-down');
    }
});

$(document).on("click", ".box_header", function (e) {
    e.stopPropagation(); // This is the preferred method.
    // This should not be used unless you do not want
    // any click events registering inside the div
});

标题和“删除我”按钮在计算机上运行正常,但在我的iPhone和iPad上无效,有没有人尝过这个?

3 个答案:

答案 0 :(得分:0)

尝试这个(应该可行,在iOS模拟器上试用 - 没有设备存在):

$('h1').on('click touchstart', function() {
    // ... your code 
});

答案 1 :(得分:0)

我知道这是一篇较旧的帖子,但我发现Mac OS和iOS不允许你进行点击操作,除非相应的图层实际上是一个html按钮。

上周我建立了一个网站后,我注意到了移动菜单可以在Windows和Android设备上使用跨页切换,但Mac OS和iOS没有切换菜单。

第二个我将图层更改为实际的html按钮,它有效!

面对苹果的Facepalm!

答案 2 :(得分:-1)

尝试使用.live()代替.on.click

$('h1').live('click', function() {
    // your code goes here...
});
相关问题