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 在移动设备上不起作用(触摸)
基础教程推荐
- 用于 Twitter 小部件宽度的 HTML/CSS 2022-01-01
- 如何使用TypeScrip将固定承诺数组中的项设置为可选 2022-01-01
- 我可以在浏览器中与Babel一起使用ES模块,而不捆绑我的代码吗? 2022-01-01
- 自定义 XMLHttpRequest.prototype.open 2022-01-01
- 如何使用JIT在顺风css中使用布局变体? 2022-01-01
- html表格如何通过更改悬停边框来突出显示列? 2022-01-01
- Chart.js 在线性图表上拖动点 2022-01-01
- Electron 将 Node.js 和 Chromium 上下文结合起来意味着 2022-01-01
- 直接将值设置为滑块 2022-01-01
- Vue 3 – <过渡>渲染不能动画的非元素根节点 2022-01-01