タブレット android4.1 chromeで
index.html
<!DOCTYPE html> <html lang="ja"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <meta http-equiv="Content-Language" content="ja"> <meta http-equiv="content-style-type" content="text/css"/> <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no"> <meta name="apple-mobile-web-app-capable" content="yes"> <meta name="robots" content="noimageindex"> <meta name="robots" content="noindex"> <title>タイトル</title> <script type='text/javascript' src="js/jquery-2.1.4.min.js"></script> <script type='text/javascript' src='js/common.js'></script> </head> <body> <form> //中略 <button id="loginbtn">ログイン</button> </form> </body> </html>
common.js
$(document).on("click touchend","#loginbtn",function(event){ event.preventDefault(); alert(2); })
で、反応しません。click扱いとなります。
読み込まれていない、と判断したのですが、パスも間違っていません。
PC、iOSでは問題なく動作します。
android特有でしょうか?対策はございますでしょうか
しかし、下記のように直描きするとandroidでも問題なく動きます。
<!DOCTYPE html> <html lang="ja"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <meta http-equiv="Content-Language" content="ja"> <meta http-equiv="content-style-type" content="text/css"/> <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no"> <meta name="apple-mobile-web-app-capable" content="yes"> <meta name="robots" content="noimageindex"> <meta name="robots" content="noindex"> <title>タイトル</title> <script type='text/javascript' src="js/jquery-2.1.4.min.js"></script> <script> $(document).on("click touchend","#loginbtn",function(event){ event.preventDefault(); alert(2); }) </script> </head> <body> //中略 <button id="loginbtn">ログイン</button> </body> </html>
その他、下記も試しましたがダメでした。
common.js
$(document).on("touchstart","#loginbtn",function(event){ event.preventDefault(); }).on("click touchend","#loginbtn",function(){ alert(2); })
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。