phonegap does not trigger jquery click event

这一生的挚爱 提交于 2019-12-25 16:57:06

问题


The example is here http://jsfiddle.net/V3qb9/57/. It runs perfectly on desktop and jsfiddle -- whenever I change the radio button, an alert is popped up. But when I try it on phonegap, the click event is not triggered at all. Any thoughts why?


回答1:


i tried your code in the init method used by phonegap in body onload tag <body onload="init();"> and i was able to see the alert.

i used the example that comes with phonegap 1.9.0 for android.

i tested it on my phone (Jelly Bean).




回答2:


Are you correctly binding the the action on Device ready? I don't think $(document) works in Phonegap the way it does in a browser. According to this answer:

The relationship between Phonegap's "onBodyLoad()/onDeviceReady()" functions and Jquery's "$(document).ready()"

try this instead:

window.addEventListener('load', function () {
    document.addEventListener('deviceready', function () {
        alert("PhoneGap is now loaded!");
    }, false);
}, false);



回答3:


use

/* enter code here */ function onBodyLoad()
{       
    document.addEventListener("deviceready", onDeviceReady, false);
}function onDeviceReady()
{
    // do your thing!
    //navigator.notification.alert("Cordova is working")
}

top of your script. Hope it will work



来源:https://stackoverflow.com/questions/11659562/phonegap-does-not-trigger-jquery-click-event

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!