如何在html中保存用户响应,然后将其保存在计算机上,以便下次可以看到它?

时间:2014-06-01 07:19:12

标签: javascript html visual-studio input windows-store-apps

我对编码比较陌生。我正在创建一个Windows应用商店应用程序,我需要一些代码(JavaScript),以便当有人键入文本框然后单击按钮时,他们的输入将保存到他们的计算机上(例如,“。txt”)下次他们加载该应用页面时,他们将能够看到他们输入的内容。

以下是我的例子:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Example_Of_What_I_Have</title>

<!-- WinJS references -->
<link href="//Microsoft.WinJS.2.0/css/ui-dark.css" rel="stylesheet" />
<script src="//Microsoft.WinJS.2.0/js/base.js"></script>
<script src="//Microsoft.WinJS.2.0/js/ui.js"></script>

<!-- Example_Of_What_I_Have references -->
<link href="/css/default.css" rel="stylesheet" />
<script src="/js/default.js"></script>
</head>
<body>
<form method="POST" action="default.js">
    <input type="text" name="inputBox" /> 
    <input type="submit" name="submitbutton" value="Submit" />
</form> 
</body>
</html>

我认为JavaScript代码应该放在default.js文件中。我不知道在哪里,所以这里是:

// For an introduction to the Blank template, see the following documentation:
// http://go.microsoft.com/fwlink/?LinkId=232509
(function () {
"use strict";

var app = WinJS.Application;
var activation = Windows.ApplicationModel.Activation;

app.onactivated = function (args) {
    if (args.detail.kind === activation.ActivationKind.launch) {
        if (args.detail.previousExecutionState !==      
activation.ApplicationExecutionState.terminated) {
            // TODO: This application has been newly launched. Initialize
            // your application here.
        } else {
            // TODO: This application has been reactivated from suspension.
            // Restore application state here.
        }
        args.setPromise(WinJS.UI.processAll());
    }
};

app.oncheckpoint = function (args) {
    // TODO: This application is about to be suspended. Save any state
    // that needs to persist across suspensions here. You might use the
    // WinJS.Application.sessionState object, which is automatically
    // saved and restored across suspension. If you need to complete an
    // asynchronous operation before your application is suspended, call
    // args.setPromise().
};

app.start();

})();

提前致谢。

1 个答案:

答案 0 :(得分:1)

您可以尝试HTML5 Web Storage

示例:

// Store
localStorage.setItem("lastname", "Smith");
// Retrieve
document.getElementById("result").innerHTML=localStorage.getItem("lastname");