查看npm官网:jquery - npm
安装jQuery
npm i -g jquery
需要使用jsdom模拟document,安装jsdom
npm i -g jsdom
编码:
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 ary = [];
for (var i=0; i<100; i++) {
ary[i] = i;
}
var tempIdx=0;
$.each(ary, function(idx, val) {
//console.info('***' + idx + '【' + val + '】');
if (tempIdx > idx) {
console.error('>>>>>>>>>>>>>>>>>>>>>STOP');
return false;
}
tempIdx = idx;
});