犀牛中的 jquery
我正在尝试将 jquery 加载到 Rhino 中,如链接 here 所示。但我不断收到以下错误:
line 1086: uncaught JavaScript runtime exception: TypeError: Cannot call method "importNode" of null
我认为 jQuery 完全无法加载 - 但我不知道为什么。我使用的是作者在源代码管理中发布的相同的index.html 文件。
这是我的 Rhino 控制台的跟踪:
js> load( "/temp/env.js" );
js> window.location = '/temp/index.html';
/temp/index.html
js> load( "/temp/jquery.js" );
js: "/temp/jquery.js", line 1086: uncaught JavaScript runtime exception: TypeError: Cannot call method "importNode" of null
at /temp/jquery.js:1086
at /temp/jquery.js:1079
at /temp/jquery.js:16
at <stdin>:41
有什么想法吗?
I'm trying to load jquery into Rhino as demonstrated by this link here. But I keep getting the following error:
line 1086: uncaught JavaScript runtime exception: TypeError: Cannot call method "importNode" of null
I think it's that jQuery is failing to load altogether - but I have no idea why. I'm using the same index.html file that the author posted in source control.
Here is the trace from my Rhino console:
js> load( "/temp/env.js" );
js> window.location = '/temp/index.html';
/temp/index.html
js> load( "/temp/jquery.js" );
js: "/temp/jquery.js", line 1086: uncaught JavaScript runtime exception: TypeError: Cannot call method "importNode" of null
at /temp/jquery.js:1086
at /temp/jquery.js:1079
at /temp/jquery.js:16
at <stdin>:41
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我使用的是 env.js 文件的旧版本。事实证明,作者确实使用了它,并将其移至自己的网站等。
新内容是 这里。
我一开始使用它,它就对 jQuery 1.5 非常满意。
I was using an OLD version of the env.js file. It turns out the author's really ran with it and moved it over to it's own sites, etc, etc.
The new stuff is here.
As soon as I started using it it was golden with jQuery 1.5.
我不认为 jQuery(以及许多其他 Web JS 库)可以在 Rhino 中工作,因为 JavaScript 运行时不提供预期的“浏览器全局变量”,如“文档”、“导航器”等。您列出的错误消息表明该库正在尝试读取 Rhino 环境中不存在的某些(可能是浏览器)对象的属性(或调用方法)。
“env.js”项目应该完全执行这种浏览器环境模型,但它似乎是实验性的,可能与您尝试使用的 jQuery 版本不兼容。
I don't think jQuery (and many other web JS libraries) will work in Rhino because that JavaScript runtime doesn't provide the expected "browser globals" like "document", "navigator", etc. The error message you list indicates that the library is trying to read an attribute (or call a method) of some (presumably browser) object that doesn't exist in the Rhino environment.
The "env.js" project should do exactly this sort of browser environment mockup but it appears to be experimental and might not be compatible with the version of jQuery you're trying to use.
我使用此处的说明成功在
Rhinojs
中运行jquery
:http://geek.michaelgrace.org/2011/09/rhino-and-envjs/
我的步骤:
I succeeded in running
jquery
inRhinojs
using instructions from here:http://geek.michaelgrace.org/2011/09/rhino-and-envjs/
My steps:
我相信 jQuery 在 Rhino 中毫无用处——你既没有 DOM,也没有 Ajax。 JavaScript 5(在 Rhino 1.7R3 中受支持)有许多必需的功能,例如 JSON 全局对象或数组方法,例如 forEach() 或 map()。
I believe jQuery is useless in Rhino - you have neither DOM nor Ajax. JavaScript 5 (supported in Rhino 1.7R3) has many required fearures, like JSON global object or array methods like forEach() or map().