简体   繁体   English

jQuery Mobile按钮单击事件未在iOS设备上触发

[英]JQuery Mobile button click event not firing on iOS device

I am trying JQuery Mobile for the first time and have not been able to trigger a response to a button being pressed on my iphone 4S which runs iOS 7.1. 我第一次尝试使用JQuery Mobile,但无法触发对运行iOS 7.1的iphone 4S上按下的按钮的响应。 The click event is triggered in the browser on my computer but not on the device. 单击事件是在我的计算机上的浏览器中触发的,而不是在设备上的触发。 I can see that this is a common issue and have tried the various proposed solutions but they dont seem to work for me. 我可以看到这是一个常见问题,并尝试了各种建议的解决方案,但它们似乎对我没有用。 My code is very simple. 我的代码很简单。 The markup is 标记是

<!doctype html>
<html>
<head>
<meta charset="utf8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>title</title>

<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.css" />
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.js"></script>

<script src="javascript/idtest.js"></script>

</head>
<body>
<div data-role="page">

<div id='login'>

<center>
    <a href="#" data-role="button" id='pincodebtn'>Identify</a>
</center>

</div>

</div><!-- /page -->

</body>
</html>

And the javascript, idtest.js, is javascript idtest.js是

$(document).ready(function() {

    $('#pincodebtn').css('cursor','pointer');

    $(document).on('click','#pincodebtn',function(){    
        alert('clicked');   
    })

});

As you can see, I have tried the trick of setting the cursor to pointer. 如您所见,我尝试了将光标设置为指针的技巧。 I have also tried catching the 'vclick', 'touchstart', 'touchend' and 'tap' events. 我还尝试捕获“ vclick”,“ touchstart”,“ touchend”和“ tap”事件。 None of which trigger the alert on the iOS device. 没有一个会触发iOS设备上的警报。 Help would be appreciated. 帮助将不胜感激。

Did you try this? 你有尝试过吗?

$('#pincodebtn').on('click',function(){    
        alert('clicked');   
});

Try the below code 试试下面的代码

 $('#pincodebtn').on('click touchstart',function(){ alert('clicked'); }); 

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

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