带有node.js的jQuery插件 [英] jQuery plugins with node.js
本文介绍了带有node.js的jQuery插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在我的node.js应用程序中将jsdom与jQuery一起使用.
I'm using jQuery with jsdom in my node.js app.
此外,我想使用jQuery插件(例如jQuery.diff),但是我找不到执行该操作的方法. 有什么出路吗?
Moreover, I want to use jQuery plugins(e.g. jQuery.diff), but I cannot find how to do this. Is there any way out?
推荐答案
在文档中创建脚本标签,以将脚本加载到其中.示例:
Create a script tag in your document to load your script into it. Example:
createWindow = function(fn) {
var window = jsdom.jsdom().createWindow(),
script = window.document.createElement('script');
jsdom.jQueryify(window, function() {
script.src = 'file://' + __dirname + '/some.library.js';
script.onload = function() {
if (this.readyState === 'complete') {
fn(window);
}
}
});
}
createWindow(function(window) {
// Do your jQuery stuff:
window.$('body').hide();
});
来源: http://blog.davidpadbury.com/2010/10/03/using-nodejs-to-render-js-charts-on-server/
这篇关于带有node.js的jQuery插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文