[英]Can't change the index.html file at Cordova 3.5
I'm using Cordova 3.5
for a project and I'm not able to change the index.html
file. 我正在使用
Cordova 3.5
进行项目,但无法更改index.html
文件。 If I change that file, the device.ready
-event is not firing. 如果我更改该文件,
device.ready
-event不会触发。
The (standard) index.html file looks like that: (标准)index.html文件如下所示:
<html>
<head>
<meta charset="utf-8" />
<meta name="format-detection" content="telephone=no" />
<!-- WARNING: for iOS 7, remove the width=device-width and height=device-height attributes. See https://issues.apache.org/jira/browse/CB-4323 -->
<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" />
<meta name="msapplication-tap-highlight" content="no" />
<title>Hello World</title>
</head>
<body>
<div class="app">
<h1>Apache Cordova</h1>
<div id="deviceready" class="blink">
<p class="event listening">Connecting too Device</p>
<p class="event received">Device is Ready</p>
asfasf
</div>
</div>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/index.js"></script>
<script type="text/javascript">
app.initialize();
</script>
</body>
</html>
When I delete the div
s with id
"deviceready", "event listening" or "event received" the device.ready
event is not firing anymore. 当我删除
div
与S id
“deviceready”,“侦听事件”或“事件受了” device.ready
事件不烧了。
What causes this problem? 是什么导致此问题?
EDIT The index.js
looks like: 编辑
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 explicitly call 'app.receivedEvent(...);'
onDeviceReady: function() {
app.receivedEvent('deviceready');
alert("JO");
},
// 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);
}
};
When you remove those elements, the app.receivedEvent()
will throw an error because it's trying to manipulate elements that don't exist. 当您删除这些元素时,
app.receivedEvent()
会引发错误,因为它试图操纵不存在的元素。 This error is thrown before your alert()
call. 在您的
alert()
调用之前引发此错误。
Remove app.receivedEvent('deviceready');
删除
app.receivedEvent('deviceready');
from app.onDeviceReady()
and it should work. 从
app.onDeviceReady()
,它应该可以工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.