在前端js worker里使用dom并且加载jquery
2024-09-06 21:17:54
四个工具:
- nodejs + npm
- npm安装的jsdom
- npm安装的jquery
- npm安装的browserify
网址:
browserify: https://browserify.org/
jsdom: https://github.com/jsdom/jsdom/
安装:
npm install -g jsdom
npm install -g jquery
npm install -g browserify
代码(main.js):
const { JSDOM } = require("jsdom");
const { window } = new JSDOM("");
const document = window.document;
let $ = require("jquery")(window);
globalThis.window = window;
globalThis.document = document;
globalThis["$"] = $;
不带jquery的
```
const { JSDOM } = require("jsdom");
const { window } = new JSDOM("");
const document = window.document;
globalThis.window = window;
globalThis.document = document;
```
编译(算是?):
browserify main.js -o wdj.js
我起的名字是简写(Window Document Jquery)
让worker引入wdj.js
importScripts("wdj.js");
实际效果:
第一次写这么简洁的博文,原因是三天考完期末,有点累
最新文章
- MySQL,排序,统计行转列
- who
- UVa 10387- Billiard
- 苹果系列机型专业刷机,解锁,解ID
- HDU 5775 Bubble Sort (线段树)
- 实现c++的string的split功能
- bzoj 2401: 陶陶的难题I 数论
- 【清橙A1084】【FFT】快速傅里叶变换
- linux中VI编辑器使用个人记录
- 【C#网络基础】C# get post请求
- iOS ARC注释和错误的解决方法在使用
- frontend http 前端名字定义问题
- CNS的数据库搜索网站可用solr实现
- Sencha Cmd的简介
- 关于Docker中的Images与Containers
- Failed to call ScheduleShutdown in logind, proceeding with immediate shutdown: Access denied
- 十四、Spring Boot 日志记录 SLF4J
- 砝码组合(dfs)
- pilicat-dfs 霹雳猫-分布式文件系统
- SQL server 基本语法