onClick 不适用于移动设备(触摸) [英] onClick not working on mobile (touch)

查看:28
本文介绍了onClick 不适用于移动设备(触摸)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,我要做的是在用户单击列表项时向下滑动 div.

Ok, what im trying to do is slide a div down when the user clicks a list item.

问题是我正在使用 Selectric https://github.com/lcdsantos/jQuery-Selectric 转换 Select框到一个无序列表.因此,当用户单击源作为列表项输出的 a 时,我希望 div 向下滑动.

Problem is I am using Selectric https://github.com/lcdsantos/jQuery-Selectric which converts a Select box to an unordered list. So when the user clicks a which the source outputs as a list item I want a div to slide down.

在移动 Safari (iOS7) 上,选择框 UI 与标准选择框 UI 相同.

On mobile safari (iOS7) the selectbox UI is the same as the standard selectbox UI.

对于移动设备的 onClick,最佳做法是什么?

What is the best practice when it comes to onClick for mobile devices?

基本jquery:

$(window).load(function() {
        $('.List li').click(function() {
            $('.Div').slideDown('500');
        });
    });

您可以在此处(侧栏上的高级搜索)看到一个工作示例

You can see a working example HERE (Advanced search on the side bar)

谢谢.

推荐答案

更好的使用 touchstart 事件和 .on() jQuery 方法:

better to use touchstart event with .on() jQuery method:

$(window).load(function() { // better to use $(document).ready(function(){
    $('.List li').on('click touchstart', function() {
        $('.Div').slideDown('500');
    });
});

<小时>

而且我不明白你为什么使用 $(window).load() 方法,因为它等待页面上的所有内容都被加载,这往往很慢,而你可以使用 $(document).ready() 方法,该方法不会等待页面上的每个元素先被加载.


And i don't understand why you are using $(window).load() method because it waits for everything on a page to be loaded, this tend to be slow, while you can use $(document).ready() method which does not wait for each element on the page to be loaded first.

这篇关于onClick 不适用于移动设备(触摸)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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