jsdom是WHATWGDOM和HTML标准的JavaScript实现,主要用于io.js框架。
示例代码:
// Count all of the links from the io.js build pagevar jsdom = require("jsdom");jsdom.env( "https://iojs.org/dist/", ["https://code.jquery.com/jquery.js"], function (errors, window) { console.log("there have been", window.$("a").length - 4, "io.js releases!"); });或者:
// Run some jQuery on a html fragmentvar jsdom = require("jsdom");jsdom.env( '<p><a class="the-link" href="https://github.com/tmpvar/jsdom">jsdom!</a></p>', ["https://code.jquery.com/jquery.js"], function (errors, window) { console.log("contents of a.the-link:", window.$("a.the-link").text()); });
评论