【发布时间】:2013-09-25 17:05:05
【问题描述】:
我一直在我的 javascript 中使用“onclick”,但现在我希望它也能在 Iphone 上运行。对于支持 ontouchstart 的设备,是否有一种简单的方法可以让所有“onclick”像 ontouchstart 一样工作?
或者我是否需要将所有脚本编写两次(一次使用 onclick,另一次使用 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>
【问题讨论】:
-
不会自动点击触摸屏调度
click事件? -
好点,谢谢:)
-
@Pavlo:不,iOS 设备(iPhone、iPad 等)不会点击。
标签: javascript