您的位置:首页 > Web前端 > JavaScript

不能在WinJs中用alert! 用console代替

2012-11-28 14:14 141 查看
Thankfully there is a JavaScript console available in Visual Studio so you can simply call
console.log(). The following steps will take you that far:

感激地是这有一个js的console在VS中可以实现,所以你可以直接用console.log().下面的步骤会带你体会:

1. Create a new JavaScript (Blank Application) Project in VS11 Express.

1.创建一个新的JS项目在VS11中。

2. Add an element to your default.html page providing something to click on. You could go with boring old text, but I went for a leaf image (pictured above, download)
and i gave it an ID of “leafImage”.

2.添加一个元素到你的default.html页面以提供一个东西去点击。你可以用无聊的文本,但是我想用一个叶子的图片,然后我给它一个名为“leafImage”的ID。

3. Next add an event handler in the onmainwindowactivated function in default.js. You can remove the ActivationKind check as it doesn’t matter for this sample. Now when adding the eventHandler I skipped over ‘click’ and instead attached
to ‘MSPointerDown’ fully embracing the new Input system of Windows 8:

3.接下来在default.js的函数onmainwindowactivated中添加一个事件处理程序。你可以删除ActivationKind检验,因为它对于这个例子没多大影响。现在,当添加eventHandler我跳过了“点击”,而是连接到“MSPointerDown“完全接受新的输入系统。

default.html页面:

leafImage.addEventListener('MSPointerDown',
function(){

//alert('leaf pointerdowned');
console.log('leaf pointerdowned');

});

default.js页面:

leafImage.addEventListener('MSPointerDown',
function(){

//alert('leaf pointerdowned');
console.log('leaf pointerdowned');
var
md =
new Windows.UI.Popups.MessageDialog('Ready
for Monday?');

var
result,
resultOptions =
['Oh yeah!',
'Nooooo!'];
var
cmd;
for(var
i =
0;
i <
resultOptions.length;
i++)
{

cmd
= new
Windows.UI.Popups.UICommand();
cmd.label
= resultOptions[i];

cmd.invoked
= function(c)
{
result
= c.label;

}
md.commands.append(cmd);

}

md.showAsync().then(function
(c)
{
console.log('answer: '
+ result);

});
});
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: