我一直在撞牆,如果有人可以幫助,我會感激不盡!科爾多瓦6.3.1 android應用程序的JavaScript不解僱
我的js文件都在www/js中。 cordova.js文件是爲我生成的。
身體中的「e」只是爲了確保我的新代碼到達那裏。它是,我已經改變了幾十個版本的信件,同時試圖讓這個工作,只是爲了確保,並且它總是變化。
的index.html
<!DOCTYPE html>
<html>
<head>
<title>Device Ready Example</title>
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script type="text/javascript" charset="utf-8" src="example.js"></script>
</head>
<body onload="onLoad()">
e
</body>
</html>
example.js
function onLoad() {
document.addEventListener("deviceready", onDeviceReady, false);
}
// device APIs are available
//
function onDeviceReady() {
alert('yo');
document.addEventListener("volumedownbutton", onVolumeDown, false);
// Add similar listeners for other events
}
function onVolumeDown() {
alert('hey');
document.body.innerHTML += '<div style="position:absolute;width:100%;height:100%;opacity:0.3;z-index:100;background:#000;">asdfs</div>';
}
cordova.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 explicitly call 'app.receivedEvent(...);'
onDeviceReady: function() {
app.receivedEvent('deviceready');
},
// 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);
}
};
app.initialize();
當我火起來的應用程序,我沒有得到任何警告,而成交量下降呢沒有。這是我在控制檯中看到,當我建立
BUILD SUCCESSFUL
Total time: 4.479 secs
Built the following apk(s):
/root/hello/platforms/android/build/outputs/apk/android-debug.apk
[email protected]:~/hello# cordova -v
6.3.1
另外,我安裝的節點和科爾多瓦在僅使用命令行空白的Ubuntu 14.04數字海洋框中APK。我去哪裏看控制檯日誌?謝謝!我不知道如何在這個環境下進行調試。
你碰巧命名你的項目'科爾多瓦'?應該加載一個真正的'cordova.js'文件。你的文件被認爲是'main.js',因爲它不包含cordova js框架。 – gro
不,它的名字叫你好,因爲我正在關注hello world tutorial的官方文檔。 – user2278120
@ user2278120你在android設備上測試它嗎? – Gandhi