jquerymobile';直播';phonegap应用程序中未定义函数
jquerymobile';直播';phonegap应用程序中未定义函数,jquery,jquery-mobile,cordova,Jquery,Jquery Mobile,Cordova,我正试图通过PhoneGap2.7和jQueryMobile 1.3.1实现这一点。 我从以下index.html文件开始: <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <meta name="format-detection" content="telephone=no" /> <meta name="vie
我正试图通过PhoneGap2.7和jQueryMobile 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>
出于某种原因,当应用程序启动时,我从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
函数无法识别。
有人知道出了什么问题吗?方法在jQuery 1.9+中不再存在,它在jQuery 1.7之后就被弃用了,应该用方法替换
从jQuery1.7开始,不推荐使用.live()方法。使用.on()来
附加事件处理程序。jQuery旧版本的用户应使用
.delegate()优先于.live()
此方法提供了将委托事件处理程序附加到
页面的文档元素,它简化了事件处理程序的使用
将内容动态添加到页面时。参见对
有关详细信息,请参见.on()方法中的直接事件与委派事件
信息
根据继承方法重写.live()方法非常困难
直截了当的这些是用于所有应用程序的等效调用的模板
三种事件附件方法
更改:
$("#pauseaudio").live('tap', function() {
pauseAudio();
});
为此:
$("#pauseaudio").on('tap', function() {
pauseAudio();
});
或者,如果要委派事件,请执行以下操作:
$(document).on('tap','#pauseaudio' , function() {
pauseAudio();
});
$(document).on('tap','#pauseaudio' , function() {
pauseAudio();
});