[英]PhoneGap / Cordova “click” working in browser, but not working on Developer App?
I have managed to create a login/signup screen, which works perfectly when served by PhoneGap and viewed in a browser.我设法创建了一个登录/注册屏幕,当由 PhoneGap 提供服务并在浏览器中查看时,它可以完美运行。
However when tested on an iPhone using the PhoneGap App, the "click" function no longer works.但是,在使用 PhoneGap 应用程序在 iPhone 上进行测试时,“单击”功能不再起作用。
var myApp = new Framework7();
var $$ = Dom7;
// Handle Cordova Device Ready Event
$$(document).on('deviceready', function() {
//wait for signup page to be fully loaded
myApp.onPageInit('signup', function (page) {
//event listener for signup button
var signupButton = document.getElementById("signup");
if(signupButton) {
signupButton.addEventListener("click", signup, false);
}
//on click of signup button
function signup() {
login code here
}
});
});
I am using this "addEventListener" method instead of:我正在使用这个“addEventListener”方法而不是:
$("#signup").on("touchend", function (){signup()});
$("#signup").on("click", function (){signup()});
After they also did not work on mobile, and stumbling across this question in an attempt to find a solution:在他们也没有在移动设备上工作之后,并且在试图找到解决方案时遇到了这个问题:
cordova/phonegap onclick doesn't work cordova/phonegap onclick 不起作用
Do these methods / handlers behave differently in a browser vs on the PhoneGap app?这些方法/处理程序在浏览器和 PhoneGap 应用程序中的行为是否不同?
I had the same issue on iOS and had to add e.preventDefault() to resolve the issue.我在 iOS 上遇到了同样的问题,不得不添加 e.preventDefault() 来解决这个问题。
$('#signup').on('click', function (e) {
e.preventDefault();
signup();
});
尝试将元素#signup
设置为具有cursor:pointer
的 css 规则,然后尝试$('#signup').on('click', function(){});
Ok for me the issue was having the button events defined as a result of "window.onload" or "document.addEventListener('deviceready'", I tried both, when I placed the handler definition in my html file it worked, so looks like a bug.对我来说,问题是将按钮事件定义为“window.onload”或“document.addEventListener('deviceready'”的结果,我尝试了这两种方法,当我将处理程序定义放在我的 html 文件中时,它起作用了,所以看起来像个虫子。
So this now works,所以这现在有效,
$("#clr").on("click", function () {
$("#mylabel").html("");
});
I used the hello app when I created my project and it uses the "app" class.我在创建项目时使用了 hello 应用程序,它使用“app”类。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.