javascript - 如何使用cordova在我的index.js中添加我的功能“新页面”
问题描述
我是移动应用程序开发的新手,我想知道如何简化我的代码。我想在我的 index.js 页面中添加我的脚本。
您可以看到我的函数转到另一个正在运行的页面,但我不喜欢将我的 javascript 代码放在与我的 html/css 代码相同的页面中。
谢谢 :)
(function () {
"use strict";
document.addEventListener( 'deviceready', onDeviceReady.bind( this ), false );
function onDeviceReady() {
// Gérer les événements de suspension et de reprise Cordova
document.addEventListener( 'pause', onPause.bind( this ), false );
document.addEventListener('resume', onResume.bind(this), false);
document.getElementById("goPageOne").onclick = function goPageOne();
// TODO: Cordova a été chargé. Effectuez l'initialisation qui nécessite Cordova ici.
var parentElement = document.getElementById('deviceready');
var listeningElement = parentElement.querySelector('.listening');
var receivedElement = parentElement.querySelector('.received');
listeningElement.setAttribute('style', 'display:none;');
receivedElement.setAttribute('style', 'display:block;');
// ajout d'une fonction vibration
//navigator.vibrate(2000);
};
function onPause() {
// TODO: cette application a été suspendue. Enregistrez l'état de l'application ici.
};
function onResume() {
// TODO: cette application a été réactivée. Restaurez l'état de l'application ici.
};
//Function go to another page
});
<button id="goPageOne">Memo</button>
<script type="text/javascript">
document.getElementById("goPageOne").onclick = function () {
location.href = "../www/homememo.html";
};
</script>
解决方案
好的,科尔多瓦的 window.open 有一些东西,所以我只是用更简单的东西改变了功能,没有任何功能。我已经用一个 href 替换了这个函数,比如:
<form action="index.html">
<button type="submit" id="b1">Quitter</button>
</form>
推荐阅读
- swift - CordovaError: Promise denied with non-error: '命令的错误代码 70:
- python - 密切关注最近添加的文件的文件夹,并在 QTableView 上显示该文件中的数据
- unix - 私钥形式的openssl散列输出不应显示文件路径名称
- c# - .NET 使用可为空的引用类型实现 IEnumerator
- c# - HttpContext.Current 的非 System.Web 替代品
- node.js - 无法运行 npm start 命令(Node.js)
- python - 如何在python中箭袋图的端点绘制一个圆圈?
- node.js - Npm 链接在 Angular7 项目中不起作用
- excel - Excel在打开之间更改工作簿内的数字格式
- coldfusion - 尝试创建一个混合了来自不同 mysql 表的数据的数组