桌面和移动设备的jQuery事件(jQuery events for both desktop and mobile)

编程入门 行业动态 更新时间:2024-10-18 21:17:14
桌面和移动设备的jQuery事件(jQuery events for both desktop and mobile)

我正在做一个完全响应的页面,并进入jQuery部分。 我的问题是如何做包括移动和桌面使用的事件。 我查看了jQuery 1.11.1文件,发现没有“触摸”的痕迹。 我想我可以用mousedown作为开始。 什么是最佳做法?

$('.touch-me').on('mousedown, click', function () { console.log('touch me'); });

I'm doing a fully responsive page and got to the jQuery part. My question is how to do events that cover both mobile and desktop usage. I have looked in jQuery 1.11.1 file and found no trace of "touch". I figure that I could use mousedownas a start. What is best practice when it comes to this?

$('.touch-me').on('mousedown, click', function () { console.log('touch me'); });

最满意答案

你可以使用touchstart:

$('.touch-me').on('mousedown touchstart', function () { console.log('touch me'); });

PS:如果你也需要点击事件,那么使用它而不用逗号分隔它(只是你需要的空间)。

You can use touchstart:

$('.touch-me').on('mousedown touchstart', function () { console.log('touch me'); });

PS: If you need click event too then use it without separating it with a comma (just a space you need).

更多推荐

jQuery,电脑培训,计算机培训,IT培训"/> <meta name="description" cont

本文发布于:2023-08-07 14:47:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1464562.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:桌面   事件   设备   mobile   jQuery

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!