Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我目前正在使用 HTML 和 JavaScript。我是初学者。我想在我的 html 文件中的按钮的 onclick 事件中打开一个 javascript 文件。有什么方法可以做到这一点。请帮助我。
提前致谢。
它认为你的意思是“加载”而不是打开
您可以使用以下代码动态“加载”JS文件
var fileref = document.createElement('script') fileref.setAttribute("type","text/javascript") fileref.setAttribute("src", yourfilename)