2014-01-21 72 views
1

新的SO,如果已经得到解答,很抱歉!WinJS.Namespace.define不能正常工作

无论如何,我开始学习如何开发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(/页/打招呼/你好.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..."; 
    }); 
}; 
}); 

我在做什么错了?提前致谢!

回答

1

您未将脚本文件("/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> 
+0

非常感谢!这是一个显而易见的错误,但它让我疯狂...... –