我试图让这个示例与 phonegap 2.7 和 jquery mobile 1.3.1 一起使用。我从以下 index.html 文件开始:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="format-detection" content="telephone=no" />
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
<link rel="stylesheet" type="text/css" href="css/index.css" />
<link rel="stylesheet" type="text/css" href="css/jquery.mobile-1.3.1.min.css" />
<title>Hello World</title>
<script type="text/javascript" src="js/lib/jquery/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="js/lib/jquery-mobile/jquery.mobile-1.3.1.min.js"></script>
<script type="text/javascript" src="cordova-2.7.0.js"></script>
<script type="text/javascript" src="js/index.js"></script>
<script type="text/javascript">
app.initialize();
</script>
</head>
<body>
<div data-role="page" data-theme="a" id="page-home">
<div data-role="header" data-nobackbtn="true" data-theme="e">
<h1>Hello world app</h1>
</div> <!-- /header -->
<div data-role="content" id="content-manual" data-theme="a">
<div data-role="button" id="playaudio" data-theme="e">Play</div>
<div data-role="button" id="pauseaudio" data-theme="e">Pause</div>
<div data-role="button" id="stopaudio" data-theme="e">Stop</div>
<div class="ui-grid-a">
<div class="ui-block-a"> Current: <span id="audio_position">0 sec</span></div>
<div class="ui-block-b">Total: <span id=media_dur>0</span> sec</div>
</div><!-- /grid-a -->
</div>
</div>
</body>
</html>
以及以下 index.js 文件:
var app = {
// Application Constructor
initialize: function() {
this.bindEvents();
},
// Bind Event Listeners
//
// Bind any events that are required on startup. Common events are:
// 'load', 'deviceready', 'offline', and 'online'.
bindEvents: function() {
document.addEventListener('deviceready', this.onDeviceReady, false);
},
// deviceready Event Handler
//
// The scope of 'this' is the event. In order to call the 'receivedEvent'
// function, we must explicity call 'app.receivedEvent(...);'
onDeviceReady: function() {
app.receivedEvent('deviceready');
$('#page-home').live('pageinit',function(){
console.log("Hello world!");
$("#playaudio").live('tap', function() {
// Note: two ways to access media file: web and local file
var src = 'http://audio.ibeat.org/content/p1rj1s/p1rj1s_-_rockGuitar.mp3';
// local (on device): copy file to project's /assets folder:
// var src = '/android_asset/spittinggames.m4a';
playAudio(src);
});
$("#pauseaudio").live('tap', function() {
pauseAudio();
});
$("#stopaudio").live('tap', function() {
stopAudio();
});
});
},
// Update DOM on a Received Event
receivedEvent: function(id) {
// var parentElement = document.getElementById(id);
// var listeningElement = parentElement.querySelector('.listening');
// var receivedElement = parentElement.querySelector('.received');
//
// listeningElement.setAttribute('style', 'display:none;');
// receivedElement.setAttribute('style', 'display:block;');
//
console.log('Received Event: ' + id);
}
};
出于某种原因,当应用程序启动时,我从 Web 控制台看到一条错误消息:
TypeError: Result of expression '$('#page-home').live' [undefined] is not a function. at file:///android_asset/www/js/index.js:44
作为记录,我知道 jquery mobile 已成功加载,但由于某种原因,该live
功能无法识别。有谁知道出了什么问题?