JavaScript で「onclick」を使用してきましたが、iPhone でも動作するようにしたいと考えています。ontouchstart をサポートするデバイスで、すべての「onclick」を ontouchstart のように動作させる簡単な方法はありますか?
それとも、すべてのスクリプトを 2 回 (1 つは onclick を使用し、もう 1 つは ontouchstart を使用する) 記述する必要がありますか? :S
注: jquery やその他のライブラリは使用したくありません。
<!DOCTYPE html>
<title>li:hover dropdown menu on mobile devices</title>
<script>
window.onload = function () {
if ('ontouchstart' in window) {
// all "onclick" should work like "ontouchstart" instead
}
document.getElementById('hbs').onclick = function () {
alert('element was clicked');
}
}
</script>
<a id=id1 href=#>button</a>