javascript 如何在触摸屏iphone上实现onmousedown和onmouseup
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21009821/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to implement a onmousedown and onmouseup on a touch screen iphone
提问by user3175352
I've very new to HTML/Java but am learning...
我对 HTML/Java 很陌生,但正在学习......
I want to develop a button on an iphone that runs a java script command when press and when it is released. I've done this find using onmousedown and onmouseup attributes, but this does not work the same.
我想在 iPhone 上开发一个按钮,该按钮在按下和释放时运行 java 脚本命令。我已经使用 onmousedown 和 onmouseup 属性完成了这个查找,但这不起作用。
could someone please point me in the right direction as to how to do this same thing on the iphone?
有人可以指出我如何在 iphone 上做同样的事情的正确方向吗?
回答by Doorknob
The equivalent for onmousedown
on touchscreen devices is ontouchstart
, and the equivalent of onmouseup
is ontouchend
.
为等效onmousedown
在触摸屏设备是ontouchstart
,和等效的onmouseup
是ontouchend
。
If you would also like to detect dragging, you could use ontouchmove
which is fired every time you move your finger after touching the screen.
如果您还想检测拖动,您可以使用ontouchmove
which 在每次触摸屏幕后移动手指时触发。
回答by Zectbumo
You might be interested in onpointerup
and onpointerdown
events which will work on both touch and non touch devices. Check browser support
您可能会感兴趣的onpointerup
和onpointerdown
将在触摸屏以及非触摸设备的工作活动。检查浏览器支持