新来的,如果已经回答了,抱歉!
不管怎样,我开始学习如何开发 Windows 应用商店应用程序,我们的第一个作业必须用 JavaScript/HTML5 开发。所以,我需要为这个特定项目使用 WinJS.Namespace.define,但它似乎对我不起作用。
我正在尝试创建一个在 hello.html (/pages/hello/hello.html) 中按下时显示文本的按钮:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>hello</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>
<link href="/css/default.css" rel="stylesheet"/>
<link href="hello.css" rel="stylesheet" />
<script src="hello.js"></script>
<body>
<div class="hello fragment">
<header aria-label="Header content" role="banner">
<button data-win-control="WinJS.UI.BackButton"></button>
<h1 class="titlearea win-type-ellipsis">
<span class="pagetitle">TotalExam</span>
</h1>
</header>
<section aria-label="Main content" role="main">
<fieldset>
<legend>Inicio de sesión</legend>
<input id="dfEntrar" type="button" value="Entrar" />
</fieldset>
<div id="prueba"></div>
</section>
</div>
</body>
hello.js (/pages/hello/hello.js) 有以下代码:
(function () {
"use strict";
WinJS.UI.Pages.define("/pages/hello/hello.html", {
ready: function (element, options) {
Accion.Loguear();
},
});
})();
最后, acciones.js (/js/MyScripts/acciones.js) 包含命名空间定义和文本代码:
(function () {
WinJS.Namespace.define("Accion", {
Loguear: fLogin
});
$ = function (val) {
return document.querySelector(val);
};
function fLogin() {
$("#dfEntrar").addEventListener("click", function() {
$("#prueba").innerText = "Probando...";
});
};
});
我究竟做错了什么?提前致谢!
最佳答案
您没有将脚本文件 ( "/js/MyScripts/acciones.js"
) 加载到页面上。 WinJs 应用程序不会自动加载脚本。
加载前 hello.js
添加另一个 script
标签加载另一个文件:
<link href="hello.css" rel="stylesheet" />
<script src="/js/MyScripts/acciones.js"></script>
<script src="hello.js"></script>
关于javascript - WinJS.Namespace.define 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21253250/