简体   繁体   English

Android点击事件div元素

[英]Android click event div element

I am having the following issue with click/touchstart event on Android (as far as I know only happening on Android), 1. the element triggers a modal window. 我在Android上的click / touchstart事件中遇到以下问题(据我所知,仅在Android上发生),1.元素触发了模式窗口。 2. one of the buttons/links inside this modal gets triggered instantly without giving the user the option to make a choice. 2.该模式内的按钮/链接之一会立即触发,而无需让用户选择。

It is of course required for the visitor/user to view the modal content before being redirected to a link to another page from one of those buttons. 当然,访问者/用户必须先查看模式内容,然后才能从这些按钮之一将其重定向到另一个页面的链接。

I believe this is due to the 'touchstart' event bind to this div, which I am using since click events on divs for touch devices don't work. 我相信这是由于绑定到此div的'touchstart'事件引起的,因为触摸设备的div上的click事件不起作用,因此我正在使用该事件。

I am using jQuery to make this work, and on iOS there doesn't seem to appear any issue. 我正在使用jQuery来完成这项工作,并且在iOS上似乎没有出现任何问题。

$(document).on('click touchstart','.mydiv', function(e) {
    e.preventDefault();
    // open modal
});

Any suggestions please. 有任何建议请。

Try this: 尝试这个:

$(.mydiv).on('touchstart', function(e) {
  e.preventDefault();
   // open modal
});

cheers 干杯

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM