• <small id='l1iiJ'></small><noframes id='l1iiJ'>

    1. <tfoot id='l1iiJ'></tfoot>
      <i id='l1iiJ'><tr id='l1iiJ'><dt id='l1iiJ'><q id='l1iiJ'><span id='l1iiJ'><b id='l1iiJ'><form id='l1iiJ'><ins id='l1iiJ'></ins><ul id='l1iiJ'></ul><sub id='l1iiJ'></sub></form><legend id='l1iiJ'></legend><bdo id='l1iiJ'><pre id='l1iiJ'><center id='l1iiJ'></center></pre></bdo></b><th id='l1iiJ'></th></span></q></dt></tr></i><div id='l1iiJ'><tfoot id='l1iiJ'></tfoot><dl id='l1iiJ'><fieldset id='l1iiJ'></fieldset></dl></div>
      <legend id='l1iiJ'><style id='l1iiJ'><dir id='l1iiJ'><q id='l1iiJ'></q></dir></style></legend>

      • <bdo id='l1iiJ'></bdo><ul id='l1iiJ'></ul>

        如何在 Windows8 商店应用程序的 Javascript/HTML5 中设置全局变量

        时间:2023-09-29

            <tfoot id='Q6yt4'></tfoot>
            <i id='Q6yt4'><tr id='Q6yt4'><dt id='Q6yt4'><q id='Q6yt4'><span id='Q6yt4'><b id='Q6yt4'><form id='Q6yt4'><ins id='Q6yt4'></ins><ul id='Q6yt4'></ul><sub id='Q6yt4'></sub></form><legend id='Q6yt4'></legend><bdo id='Q6yt4'><pre id='Q6yt4'><center id='Q6yt4'></center></pre></bdo></b><th id='Q6yt4'></th></span></q></dt></tr></i><div id='Q6yt4'><tfoot id='Q6yt4'></tfoot><dl id='Q6yt4'><fieldset id='Q6yt4'></fieldset></dl></div>

            <small id='Q6yt4'></small><noframes id='Q6yt4'>

              <bdo id='Q6yt4'></bdo><ul id='Q6yt4'></ul>
                  <tbody id='Q6yt4'></tbody>
                • <legend id='Q6yt4'><style id='Q6yt4'><dir id='Q6yt4'><q id='Q6yt4'></q></dir></style></legend>

                  本文介绍了如何在 Windows8 商店应用程序的 Javascript/HTML5 中设置全局变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想在 .js 文件中使用全局变量.例如,

                  I want to use global variable in .js files. For example,

                  当我读取a.js + a.html"中的文件内容并保存到某个变量fileContent"中时

                  when I read a file content in " a.js + a.html " and saved into a certain variable 'fileContent'

                  那么我也想在b.js + b.html"中使用那个'fileContent'.

                  then I also want to use that 'fileContent' in " b.js + b.html ".

                  (另外,当我更改b.js + b.html"中的fileContent"时,应该会影响a.js + a.html"中的fileContent")

                  (also, when I change the 'fileContent' in "b.js + b.html", that should affect 'fileContent' in "a.js + a.html")

                  我该怎么办?

                  谢谢.

                  推荐答案

                  鉴于 Windows 8 应用程序的架构是单页模型,您无需浏览浏览器,而只需加载 HTML 片段并插入它进入 current 文档,这很容易.但是,我建议使用一些类型,而不仅仅是裸"全局变量.

                  Given that the architecture for Windows 8 Applications is the single page model, where you don't navigate the browser, but merely load a fragment of HTML and insert it into the current document, this is very easy. I would, however, recommend using some typing, rather than just a "naked" global variable.

                  文件 A (globals.js):

                  File A (globals.js):

                  WinJS.Namespace.define("MyGlobals",  {
                      variableA: null,
                  });
                  

                  在 WinJS 包含之后,将其包含在 default.html 的顶部.

                  Include this at the top of default.html after the WinJS includes.

                  文件 B (b.js):

                  File B (b.js):

                  // your other code
                  ...
                  MyGlobals.variableA = getValueFromSomewhere();
                  

                  文件 C(b.html 或 c.js):

                  File C (b.html, or c.js):

                  // your other code
                  ...
                  printSomethingAwesomeFromData(MyGlobals.variableA);
                  

                  这篇关于如何在 Windows8 商店应用程序的 Javascript/HTML5 中设置全局变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何在 Windows 8 Metro 应用程序中将 html5 画布保存为图像文件? 下一篇:当我们使用 JavaScript 创建 Metro 应用程序时,Visual Studio 11 Ultimate 中的

                  相关文章

                • <legend id='4hGkY'><style id='4hGkY'><dir id='4hGkY'><q id='4hGkY'></q></dir></style></legend><tfoot id='4hGkY'></tfoot>
                • <i id='4hGkY'><tr id='4hGkY'><dt id='4hGkY'><q id='4hGkY'><span id='4hGkY'><b id='4hGkY'><form id='4hGkY'><ins id='4hGkY'></ins><ul id='4hGkY'></ul><sub id='4hGkY'></sub></form><legend id='4hGkY'></legend><bdo id='4hGkY'><pre id='4hGkY'><center id='4hGkY'></center></pre></bdo></b><th id='4hGkY'></th></span></q></dt></tr></i><div id='4hGkY'><tfoot id='4hGkY'></tfoot><dl id='4hGkY'><fieldset id='4hGkY'></fieldset></dl></div>

                  <small id='4hGkY'></small><noframes id='4hGkY'>

                  • <bdo id='4hGkY'></bdo><ul id='4hGkY'></ul>