加载页面后访问您的 dom 元素。这可以在 page.ready 事件处理程序中完成。
page.js:
WinJS.UI.Pages.define('/pages/mypage/page.html',
{
ready: function onready(element, options)
{
// all dom elements with id will have the respective variables available here.
// need not create variable for canvas.
var context = canvas.getContext('2d');
}
});
page.html:
<html>
<head>
<title></title>
<link href="/pages/mypage/mypage.css" rel="stylesheet" />
<script src="/pages/mypage/mypage.js" type="text/javascript"></script>
</head>
<body>
<div class="mypage fragment">
<header role="banner">
<button class="win-backbutton" aria-label="Back" disabled type="button"></button>
<h1 class="titlearea win-type-ellipsis">
<span class="pagetitle">My Page</span>
</h1>
</header>
<section aria-label="Main content" role="main">
<canvas id="canvas">
</canvas>
</section>
</div>
</body>