Javascript Winjs从PageControl导航不';t火灾准备事件
我正在学习在Visual studio express 2013中构建Windows 8.1导航应用程序 我在home.html中创建了一个按钮,并绑定了一个click事件来执行对名为Javascript Winjs从PageControl导航不';t火灾准备事件,javascript,windows,dom-events,microsoft-metro,winjs,Javascript,Windows,Dom Events,Microsoft Metro,Winjs,我正在学习在Visual studio express 2013中构建Windows 8.1导航应用程序 我在home.html中创建了一个按钮,并绑定了一个click事件来执行对名为htmlcontrols的pageControl元素的导航(导航工作正常)。接下来,我创建了一个名为otherpage的新pageControl,并添加了另一个按钮,但这次是在htmlcontrols中。我将另一个单击事件绑定到此按钮,以从htmlcontrols导航到其他页面 导航流应为: 主页(单击)->HTM
htmlcontrols
的pageControl
元素的导航(导航工作正常)。接下来,我创建了一个名为otherpage
的新pageControl
,并添加了另一个按钮,但这次是在htmlcontrols
中。我将另一个单击事件绑定到此按钮,以从htmlcontrols
导航到其他页面
导航流应为:主页(单击)->HTMLControl(单击)->其他页面
第二个导航不起作用,我尝试在otherpage.js上的ready事件中放置一个调试器,但没有启动 htmlcontrols.html:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>htmlcontrols</title>
<link href="htmlcontrols.css" rel="stylesheet" />
<script src="htmlcontrols.js"></script>
</head>
<body>
<div class="htmlcontrols fragment">
<header class="page-header" aria-label="Header content" role="banner">
<button class="back-button" data-win-control="WinJS.UI.BackButton"></button>
<h1 class="titlearea win-type-ellipsis">
<span class="pagetitle">Welcome to htmlcontrols</span>
</h1>
</header>
<section class="page-section" aria-label="Main content" role="main">
<button id="newButton">Link to another page!</button>
</section>
</div>
</body>
</html>
HTMLControl
欢迎使用HTMLControl
链接到另一个页面!
htmlcontrols.js:
// For an introduction to the Page Control template, see the following documentation:
// http://go.microsoft.com/fwlink/?LinkId=232511
(function () {
"use strict";
var nav = WinJS.Navigation;
WinJS.UI.Pages.define("/pages/htmlcontrols.html", {
// This function is called whenever a user navigates to this page. It
// populates the page elements with the app's data.
ready: function (element, options) {
// NEVER REACHES THIS POINT
debugger;
newButton.addEventListener("click", function (e) {
nav.navigate("/pages/otherpage/otherpage.html");
}, false);
},
unload: function () {
// TODO: Respond to navigations away from this page.
},
updateLayout: function (element) {
/// <param name="element" domElement="true" />
// TODO: Respond to changes in layout.
}
});
})();
//有关页面控件模板的介绍,请参阅以下文档:
// http://go.microsoft.com/fwlink/?LinkId=232511
(功能(){
“严格使用”;
var nav=WinJS.Navigation;
define(“/Pages/htmlcontrols.html”{
//每当用户导航到此页面时,都会调用此函数。它
//用应用程序的数据填充页面元素。
就绪:功能(元素、选项){
//从未达到这一点
调试器;
newButton.addEventListener(“单击”,函数(e){
导航(“/pages/otherpage/otherpage.html”);
},假);
},
卸载:函数(){
//TODO:响应离开此页面的导航。
},
updateLayout:函数(元素){
///
//TODO:响应布局中的更改。
}
});
})();
找到了!
在htmlcontrols.js中,WinJS.UI.Pages.define()中的uri是错误的。很高兴您找到了答案。更具体地说,页面的.html文件在项目中的位置和WinJS.UI.Pages.define中的相对URI必须匹配,才能将页面控件中的代码与html文件正确关联。否则会发生的情况是HTML加载得很好,但是当WinJS查找定义的页面控件时,它找不到匹配项,因此不会触发任何这些事件 请注意,如果为Navigator.navigate提供了错误的URI,但它找不到该文件,则会引发异常。但是Pages.define中有错误的UI不会引发错误,因为WinJS假设页面在没有事件处理程序的情况下可以正常运行