尝试使用 document.toString
写出已编辑的 JSDOM 实例,但它序列化为 [object Document]
。我们应该调用什么方法来获取 String
形式的文档标记,或者是否有更好的方法在 Node.js 中将其序列化。目前我正在调用此电话:
fs.writeFileSync(target, document.toString());
最佳答案
根据文档 ( https://github.com/jsdom/jsdom ):
const dom = new JSDOM(`<!DOCTYPE html>hello`);
dom.serialize() === "<!DOCTYPE html><html><head></head><body>hello</body></html>";
// Contrast with:
dom.window.document.documentElement.outerHTML === "<html><head></head><body>hello</body></html>";
关于javascript - 序列化已编辑的 JSDOM 文档?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49185599/