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 在移动设备上不起作用(触摸)


- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01
- 失败的 Canvas 360 jquery 插件 2022-01-01
- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
- 400或500级别的HTTP响应 2022-01-01
- addEventListener 在 IE 11 中不起作用 2022-01-01
- Flexslider 箭头未正确显示 2022-01-01
- Fetch API 如何获取响应体? 2022-01-01
- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07
- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01
- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01