[英]Cordova.js linked, deviceready not firing
我已經鏈接了cordova.js,我有app.initialize();
,並且deviceready不會啟動。 有人知道為什么嗎?
JS:
var app = {
initialize: function() {
this.bindEvents();
},
bindEvents: function() {
document.addEventListener('deviceready', this.onDeviceReady, false);
},
onDeviceReady: function() {
app.receivedEvent('deviceready');
document.getElementById("finishbutton").addeventlistener("click", greet)
},
function greet(){
alert("The button works.")
}
};
app.initialize();
HTML:
<html>
<head>
<meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *">
<meta name="format-detection" content="telephone=no">
<meta name="msapplication-tap-highlight" content="no">
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
<link rel="stylesheet" type="text/css" href="css/index.css">
<title>Hello World</title>
</head>
<body>
<div class="app">
<h1>Apache Cordova</h1>
<div id="deviceready" class="blink">
<p class="event listening">Connecting to Device</p>
<p class="event received">Device is Ready</p>
</div>
</div>
<button id = "finishbutton">Finish</button>
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script type="text/javascript" src="js/index.js"></script>
<script type="text/javascript">
app.initialize();
</script>
</body>
</html>
如果設備就緒,我應該可以按“完成”按鈕並收到警報。 相反,它只是鎖定“連接到設備”。
嘗試這個:
var app = {
initialize: function() {
this.bindEvents();
},
bindEvents: function() {
document.addEventListener('deviceready', this.onDeviceReady, false);
},
onDeviceReady: function() {
app.receivedEvent('deviceready');
document.getElementById("finishbutton").addEventListener("click", this.greet);
/*here you were missing the ";" and "Event" and "Listener" should be
capitalized */
},
greet: function(){
alert("The button works."); /*here you were missing the ";", too. additionally i think you should use greet: function() */
}
};
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.