gpt4 book ai didi

javascript - 无法更改 Cordova 3.5 的 index.html 文件

转载 作者:行者123 更新时间:2023-11-30 17:27:01 24 4
gpt4 key购买 nike

我正在为一个项目使用 Cordova 3.5,但我无法更改 index.html 文件。如果我更改该文件,device.ready 事件不会触发。

(标准)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>

当我删除带有 id“deviceready”、“事件监听”或“事件接收”的 divdevice.ready 事件不再开火了。

是什么导致了这个问题?

编辑 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);
}
};

最佳答案

当您删除这些元素时,app.receivedEvent() 将抛出错误,因为它试图操作不存在的元素。此错误在您的 alert() 调用之前抛出。

app.onDeviceReady() 中删除 app.receivedEvent('deviceready'); 它应该可以工作。

关于javascript - 无法更改 Cordova 3.5 的 index.html 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24041772/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com