如何在 Chrome 控制台中包含 JavaScript 文件或库? [英] How to include JavaScript file or library in Chrome console?
本文介绍了如何在 Chrome 控制台中包含 JavaScript 文件或库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有更简单的(也许是原生的?)方法可以在 Google Chrome 浏览器中包含外部脚本文件?
Is there a simpler (native perhaps?) way to include an external script file in the Google Chrome browser?
目前我是这样做的:
document.head.innerHTML += '<script src="http://example.com/file.js"></script>';
推荐答案
appendChild()
是一种更原生的方式:
appendChild()
is a more native way:
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'script.js';
document.head.appendChild(script);
这篇关于如何在 Chrome 控制台中包含 JavaScript 文件或库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文