phonegap-event

本文介绍如何在PhoneGap 2.0.0版本中监听各种设备事件,包括设备准备、暂停、恢复、网络状态变化、电池状态、菜单按钮等,并通过jQuery和Cordova API实现事件响应。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

监听各类事件,我用的是phonegap2.0.0的版本,越高级的版本支持功能就越多。

<!DOCTYPE html>
<html>
<head>
<title>Event Example</title>

<script type="text/javascript" charset="utf-8" src="jquery-1.8.1.min.js"></script>
<script type="text/javascript" charset="utf-8" src="cordova-2.0.0.js"></script>
<script type="text/javascript" charset="utf-8">


// Wait for Cordova to load
// details plz see http://docs.phonegap.com/en/2.0.0/cordova_events_events.md.html#Events
document.addEventListener("deviceready", onDeviceReadyEvent, false);
document.addEventListener("pasue", onPasueEvent, false);
document.addEventListener("resume", onResumeEvent, false);
document.addEventListener("online", onlineEvent, false);
document.addEventListener("offline", offlineEvent, false);
document.addEventListener("backbutton", onBackbuttonEvent, false);
document.addEventListener("batterycritical", onBatterycriticalEvent, false);
document.addEventListener("batterylow", onBatterylowEvent, false);
document.addEventListener("batterystatus", onBatterystatusEvent, false);
document.addEventListener("menubutton", onMenubuttonEvent, false);
document.addEventListener("startcallbutton", onStartcallbuttonEvent, false);
document.addEventListener("volumedownbutton", onVolumedownbuttonEvent, false);
document.addEventListener("volumeupbutton", onVolumeupbuttonEvent, false);


// Cordova is ready
//
function onDeviceReadyEvent() {
$("#msg").append("==>onDeviceReadyEvent<p/>");
}

function onPasueEvent() {
$("#msg").append("==>onPasueEvent<p/>");
}

function onResumeEvent() {
$("#msg").append("==>onResumeEvent<p/>");
}

function onlineEvent() {
$("#msg").append("==>onlineEvent<p/>");
}

function offlineEvent() {
$("#msg").append("==>offlineEvent<p/>");
}

function onBackbuttonEvent() {
$("#msg").append("==>onBackbuttonEvent<p/>");
}

function onBatterycriticalEvent() {
$("#msg").append("==>onBatterycriticalEvent<p/>");
}

function onBatterylowEvent() {
$("#msg").append("==>onBatterylowEvent<p/>");
}

function onBatterystatusEvent() {
$("#msg").append("==>onBatterystatusEvent<p/>");
}

function onMenubuttonEvent() {
$("#msg").append("==>onMenubuttonEvent<p/>");
}

function onStartcallbuttonEvent() {
$("#msg").append("==>onStartcallbuttonEvent<p/>");
}

function onVolumedownbuttonEvent() {
$("#msg").append("==>onVolumedownbuttonEvent<p/>");
}

function onVolumeupbuttonEvent() {
$("#msg").append("==>onVolumeupbuttonEvent<p/>");
}

</script>
</head>
<body>
<h1>Event Example</h1>
<div id="msg"></div>
</body>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值