简体   繁体   English

PhoneGap / Cordova 在浏览器中“点击”工作,但在开发者应用程序中不起作用?

[英]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.

相关问题 Phonegap通知在Phonegap开发人员Android应用程序中不起作用 - Phonegap Notification not working in phonegap developer android app 超链接单击事件不适用于phonegap,但可在浏览器上使用 - Hyperlink click event not working with phonegap but works on browser cordova(phonegap):在画布内拖动图像在浏览器中工作正常,但在移动设备中不能正常工作 - cordova(phonegap): drag image inside canvas working fine in browser but not in mobile AJAX发布请求可在浏览器中运行,而不是在Phonegap App上运行 - AJAX post request working in browser, not on Phonegap App 使用Cordova Phonegap 3.3.0检查iOS应用程序上的互联网连接是否正常 - Check internet connection on iOS app with Cordova Phonegap 3.3.0 not working 在(浏览器)笔记本电脑上工作的phonegap地图应用程序,但在Android手机上不工作 - phonegap map app working on (browser) laptop but not working on Android phone PhoneGap / Cordova CanvasCamera插件不起作用 - PhoneGap/Cordova CanvasCamera Plugin not working PhoneGap Cordova> 3.1.0 inAppBrowser无法正常工作 - PhoneGap Cordova > 3.1.0 inAppBrowser not working jQuery Mobile不适用于Phonegap / Cordova - Jquery Mobile Not working with Phonegap/Cordova Phonegap / Cordova CSS无法正常工作 - Phonegap / Cordova css not working correctly
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM