doracoin a révisé ce gist . Aller à la révision
1 file changed, 1 insertion, 1 deletion
useMD5.js
| @@ -12,7 +12,7 @@ | |||
| 12 | 12 | console.log('Now, You can use "CryptoJS" const'); | |
| 13 | 13 | // 在这里可以执行依赖于crypto-js的代码 | |
| 14 | 14 | ||
| 15 | - | function makeMD5(str) { | |
| 15 | + | window.makeMD5 = function makeMD5(str) { | |
| 16 | 16 | // 使用CryptoJS计算MD5 | |
| 17 | 17 | const hash = CryptoJS.MD5(str).toString(); | |
| 18 | 18 | console.log(hash); // 输出MD5值 | |
doracoin a révisé ce gist . Aller à la révision
1 file changed, 33 insertions
useMD5.js(fichier créé)
| @@ -0,0 +1,33 @@ | |||
| 1 | + | (function() { | |
| 2 | + | // 创建一个新的script元素 | |
| 3 | + | var script = document.createElement('script'); | |
| 4 | + | script.type = 'text/javascript'; | |
| 5 | + | ||
| 6 | + | // 设置src属性为外部脚本的链接 | |
| 7 | + | script.src = 'https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.0.0/crypto-js.min.js'; | |
| 8 | + | ||
| 9 | + | // 监听脚本加载完成事件 | |
| 10 | + | script.onload = function() { | |
| 11 | + | console.log('crypto-js script loaded and ready to use!'); | |
| 12 | + | console.log('Now, You can use "CryptoJS" const'); | |
| 13 | + | // 在这里可以执行依赖于crypto-js的代码 | |
| 14 | + | ||
| 15 | + | function makeMD5(str) { | |
| 16 | + | // 使用CryptoJS计算MD5 | |
| 17 | + | const hash = CryptoJS.MD5(str).toString(); | |
| 18 | + | console.log(hash); // 输出MD5值 | |
| 19 | + | } | |
| 20 | + | }; | |
| 21 | + | ||
| 22 | + | // 监听脚本加载错误事件 | |
| 23 | + | script.onerror = function() { | |
| 24 | + | console.error('crypto-js script failed to load'); | |
| 25 | + | // 处理加载失败的情况 | |
| 26 | + | }; | |
| 27 | + | ||
| 28 | + | // 将script元素添加到文档的head中 | |
| 29 | + | document.head.appendChild(script); | |
| 30 | + | ||
| 31 | + | // 也可以选择添加到body中,这取决于您的需求 | |
| 32 | + | // document.body.appendChild(script); | |
| 33 | + | })(); | |