【发布时间】:2021-02-15 15:36:41
【问题描述】:
我正在尝试在三星手表(可穿戴 4.0)上开发一个小应用程序。这个想法很简单,人们每次打开应用程序时都必须回答一个问题。 这是基本的html代码:
<html>
<style>
h1 {color: white; font-family: courier new; font-size:150%; text-align: center; position: absolute; top: 5%; left: 14%}
body {background-color: SkyBlue;}
#button1 {font-size: 20px; color:white; position:absolute; top: 30%; left: 23%; width: 200px; height: 55px; background-color: black; border-color: black;}
#button2 {font-size: 20px; color:white; position:absolute; top: 70%; left: 23%; width: 200px; height: 55px; background-color: black; border-color: black;}
</style>
<body>
<h1>Es tu concentré <br> sur un élément extérieur?</h1>
<button id="button1" onclick="location.href = 'Third.html';">Mon attention est captée</button>
<button id="button2" onclick="location.href = 'Third.html';">Rien ne capte mon attention</button>
</body>
</html>
在正文中,我放置了一个脚本,其中事件(单击特定按钮)记录在一个数组中:
var data = [];
document.getElementById("button1").addEventListener("click", function(){
date = new Date();
data.push("Concentré");
data.push(date);
document.getElementById("demo").innerHTML = data;
});
document.getElementById("button2").addEventListener("click", function(){
date = new Date();
data.push("Pas Concentré");
data.push(date);
document.getElementById("demo1").innerHTML = data;
});
最后,我想将变量“data”保存在一个 txt 文件中,所以我复制/浪费了我在 Tizen 文档中找到的内容:
var documentsDir;
documentsDir.createFile("MWRecord.txt");
function onsuccess(files) {
var testFile = documentsDir.createFile("test.txt");
if (testFile != null) {
testFile.openStream("w", function(fs) {
fs.write(data);
fs.close();
});
}
};
function onerror(error) {
console.log("The error " + error.message + " occurred when listing the files in the selected folder");
};
tizen.filesystem.resolve(
'documents',
function(dir) {
documentsDir = dir;
dir.listFiles(onsuccess, onerror);
});
但是,当使用模拟器尝试时,不会创建任何文件。有人知道我如何创建一个文件来保存记录的事件吗?
非常感谢您的帮助!!!
雨果
【问题讨论】:
标签: tizen tizen-web-app tizen-emulator