NodeJs中使用jQuery
程序员文章站
2022-06-29 18:25:17
...
// const $ = require('jquery')(require("jsdom").jsdom().defaultView);//老版本
// 参考https://www.cnblogs.com/DonaHero/p/10001804.html
const jsdom = require('jsdom');
const {JSDOM} = jsdom;
const {document} = (new JSDOM('<!doctype html><html><body></body></html>')).window;
global.document = document;
const window = document.defaultView;
const $ = require('jquery')(window);
var navigator={};
navigator.userAgent ='Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36'
//以上定义jQuery 修改导出函数为$
console.log(window.location.href);
//注意写法
(function($) {
console.log(navigator.userAgent)
console.log($('p'))
})($);
上一篇: 炸弹人——枚举小题