Javascript PhoneGap应用程序-“;“设备日”;未调用事件侦听器
我正在使用vs2012,我正在开发一个PhoneGap应用程序,在该应用程序中,我使用以下JavaScript代码:Javascript PhoneGap应用程序-“;“设备日”;未调用事件侦听器,javascript,jquery,cordova,Javascript,Jquery,Cordova,我正在使用vs2012,我正在开发一个PhoneGap应用程序,在该应用程序中,我使用以下JavaScript代码: document.addEventListener("deviceready", onDeviceReady, false); function onDeviceReady() { // alert("hh"); console.log("Entering index.html.onDeviceReady"); //v
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady()
{
// alert("hh");
console.log("Entering index.html.onDeviceReady");
//var element = document.getElementById('deviceProperties');
var html = "";
html = html + "<li>" + 'Device Name: ' + device.name + "</li>";
html = html + "<li>" + 'Device Cordova: ' + device.cordova + "</li>";
html = html + "<li>" + 'Device Platform: ' + device.platform + "</li>";
html = html + "<li>" + 'Device UUID: ' + device.uuid + "</li>";
console.log(html);
$("#deviceProperties").html(html);
$("#deviceProperties").listview('refresh');
console.log("Exiting index.html.onDeviceReady");
}
document.addEventListener(“DeviceRady”,OnDevicerady,false);
函数ondevicerady()
{
//警报(“hh”);
log(“输入index.html.ondevicerady”);
//var元素=document.getElementById('deviceProperties');
var html=“”;
html=html+“”+”设备名称:“+Device.Name+” ”;
html=html+“”+”设备科尔多瓦:“+Device.Cordova+” ”;
html=html+“”+”设备平台:“+Device.Platform+” ”;
html=html+“”+”设备UUID:“+Device.UUID+” ”;
log(html);
$(“#设备属性”).html(html);
$(“#设备属性”).listview(“刷新”);
log(“Exiting index.html.ondevicerady”);
}
但是函数没有被调用,也没有动态添加任何元素。我做错了什么?必须完全加载页面才能调用
deviceready
事件侦听器,否则它将无法工作,因为设备尚未就绪。在脚本中,它是在页面完全加载之前调用的。试试这个:
function onLoad()
{
document.addEventListener("deviceready",onDeviceReady, true);
}
另外,在html文件中更改以下内容:
<body onload="onLoad();">
编辑:将
addEventListener
中的第三个参数更改为“true
”确保在脚本之前添加脚本type=“text/javascript”charset=“utf-8”src=“phonegap-1.0.0.js”
。但该函数不会被调用,也不会动态添加任何元素。我做错了什么?将addEventListener中的第三个参数更改为“true”。