本文介绍了错误:jQuery需要带有文档的窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
因此,直到进行npm更新为止,一切都工作得很好,而且现在情况不再像以前那样正常.
So everything was working just fine and great until doing npm update and now things do not work quite as they used to.
一些背景知识:在我的代码中,我使用jquery解析文本html.我不使用窗口,也不使用jsdom.过去这样做很正常:
A little background: in my code I use jquery to parse textual html. I do not use a window and I don't use jsdom. It used to work just fine to do this:
$ = require("jquery");
$(html).find("<h1>").html("The title");
但是现在我得到了:jQuery需要一个带有文档的窗口
But now I get this:jQuery requires a window with a document
我该如何解决?
推荐答案
node.js-jQuery定义一行:
node.js-jQuery definition in one line:
// definition
var $ = require('jquery')(require("jsdom").jsdom().parentWindow);
// usage
$("body").append("<div>TEST</div>");
console.log($("body").html());
这篇关于错误:jQuery需要带有文档的窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!