Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
512 views
in Technique[技术] by (71.8m points)

javascript - Would onClick event work on touch on touch-screen devices?

I've used onclick events in my website. But when I open it in google chromes' developer mode's mobile view, nothing happens on touch on the elements which work on click with mouse. So my question is:

Do I have to also add ontouch events along with onclick events, or onClick event work on touch on all touch-screen devices?

P.S: You can see all of my codes here: https://github.com/SycoScientistRecords/sycoscientistrecords.github.io/

Or at the live website: http://sycoscientistrecords.github.io

And no I haven't tested the website on real phone.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

onclick works fine on touchscreens; I've used it several times and have never had any problem.

You could consider using onmousedown instead of onclick. Or use jQuery to detect taps.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...