onClick not working on mobile (touch)(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 在移动设备上不起作用(触摸)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:onClick 在移动设备上不起作用(触摸)


基础教程推荐
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
- 如何在特定日期之前获取消息? 2022-01-01
- 如何使用 CSS 显示和隐藏 div? 2022-01-01
- 每次设置弹出窗口的焦点 2022-01-01
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
- Node.js 有没有好的索引/搜索引擎? 2022-01-01
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01