jQuery和Windows 8 JavaScript Metro样式应用程序
jQuery 可以在使用 JavaScript API 开发的 Windows 8 Metro 风格应用程序中使用吗?我正在查看示例,其中有很多标准 DOM 操作,例如 document.getElementById
、addEventListener
等。我想使用 jQuery 来提高工作效率。
Can jQuery be used in Windows 8 Metro-style apps developed using the JavaScript API? I'm looking at the samples, and there's a lot of standard DOM manipulation like document.getElementById
, addEventListener
, etc. I'd like to use jQuery for productivity.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
$
并不神奇。 jQuery 只是一个 JavaScript 库。它应该运行良好。唯一可能不起作用的是 cssHooks,它不会考虑其环境的任何“怪癖”。
所以,是的,如果您相信 Microsoft 能够创建一个遵循 HTML/CSS/JS 规范的环境,那么它就会起作用。
你觉得幸运吗?
The
$
is not magic. jQuery is just a javascript library. It should run fine.The only thing that might not work are cssHooks which won't take into account any 'quirks' of their environment.
So yes, it will work, if you trust Microsoft to produce an environment that follows the HTML/CSS/JS specifications.
Do you feel lucky?
是的,它可以工作,就像任何 JavaScript 库一样。我在他们在 BUILD 会议上分发的一台平板电脑上验证了这一点。
但是,不要期望使用 CDN 来加载脚本。您必须下载它,将其添加到项目中,然后在本地引用它。
Yes, it works, as will any JavaScript library. I verified it on one of the tablets they gave out at the BUILD conference.
However, do not expect to use a CDN to load in the script. You have to download it, add it to the project, and reference it locally.
tl; dr :您可以使用jQuery 1.7+,但是当涉及标记修改时(尚未完全集成)。
引用
这意味着它将起作用,但是您会遇到一些 html和dom api更改列表(MSDN)
设置
innerhtml
属性时提到了例外(其他:如果有不安全标记,则使html更安全) - 块和加载jQuery库(1.8.2)的简单事实将触发一些。如前所述,您确实需要使用库的本地副本(没有CDN)。
tl;dr : you can use jQuery 1.7+, but it's not (yet?) fully integrated when markup modification is involved.
Quote from the Dev Center (msdn)
That means that it will work, but you will encounter some non-standard behaviors as listed in the HTML and DOM API changes list (msdn)
There are exceptions mentioned when setting the
innerHtml
property (among others : Making HTML safer) if there is unsafe markup, but this is non-blocking and the simple fact of loading the jQuery library (1.8.2) will trigger a few.As mentioned before, you do need to use a local copy of the library (no CDN).
您可以使用任何 JS 库。我怀疑像 WinJS.xhr(又名“$.ajax”)这样的方法是为了让 WinJS 不依赖于 jQuery 而编写的。
You can use any JS library. I suspect that methods like WinJS.xhr (aka '$.ajax') where written so that WinJS doesnt have a dependency on jQuery.
它应该运行良好。 jQuery 只是一个库。
$('#someid')
将在内部调用document.getElementById
您可以像使用自己编写的 javascript 代码一样使用它...It should run fine. jQuery is just a library. The
$('#someid')
will internally call thedocument.getElementById
You can use it just as if you can use the javascript code you write yourself...JQuery 应该可以正常工作,但请记住,在您的示例中,有一些内置功能可以执行此类操作:
查询集合文档
JQuery should work fine but bear in mind there is some built in functionality for doing this kind of thing, in the case of your example:
Query Collection Documentation
不要使用任何 Windows 库,例如 WinJS。为什么你想要锁定自己并依赖专有代码?坚持使用常用的东西,即 HTML、CSS、JS(JQuery 或其他)。它只会让你未来的支持/开发更加可预测......
Don't use any windows libraries like WinJS. Why would you want to lock yourself and be dependent on proprietary code? Stick with the usual stuff, i.e. HTML, CSS, JS(JQuery or otherwise). It will only make your future support/dev far more predictable ...
与所有第三方 JavaScript 库一样,您应该记住一些事情。
我还编写了一个免费的 Windows 应用商店游戏工具包,它使用第三方库,您可以在此处获取免费源代码:http://win8gamekit.codeplex.com
As with all third party JavaScript libraries there are a couple of things you should keep in mind.
I have also written a free Windows Store Gaming Kit that uses third party libraries you can grab the free source for that here: http://win8gamekit.codeplex.com
其实你可以通过Visual Studio下载它。如果您下载 NuGet 包管理器。
工具->添加包和扩展
在左侧在线包中搜索 NuGet Package Manager 并安装。
然后,当您在需要 jQuery 的项目中时,右键单击您的引用并添加 NuGet 包,然后搜索 jQuery。这就是我用的。
Actually you can download it through Visual Studio. If you download NuGet Package Manager.
TOOLS->Add Packages & Extensions
Search the left online packages for NuGet Package Manager and install.
Then when in a project that you want jQuery, right click on your references and add a NuGet package, and search jQuery. That's what I use.