如何删除.getScript()加载的脚本
当我使用 .getScript('file.js')
加载脚本时,有没有办法稍后删除该脚本?有点像 clean,我说删除我之前加载的 js
When I load a script with .getScript('file.js')
is there a way to do remove that script later? sort of like a clean where I say delete the js I loaded earlier
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
getScript
不会“加载”脚本,即保留脚本;它从服务器下载脚本并立即运行。所以没有必要将其删除。但是,脚本创建的任何 DOM 对象或其定义的函数等将继续存在。删除它们需要具体了解它们是什么;也许你最好的选择是让你的脚本定义一个函数来删除脚本其余部分创建的所有内容。
getScript
doesn't "load" a script in the sense of keeping it around; it downloads the script from the server and runs it immediately. So there's no need to remove it.However, any DOM objects that the script creates, or functions it defines, etc., will continue to exist. Removing these will require knowing specifically what they are; probably your best bet is to have your script define a function that deletes all of the things that the rest of the script creates.
不幸的是,一旦代码被执行,你就无法取消执行它。
但是,如果
file.js
创建 DOM 对象,您可以通过delete object.name
删除这些对象,并且如果您使用bind()
您可以随时unbind()
它们。Unfortunately once the code has been executed you can't unexecute it.
However, if
file.js
creates DOM objects, you can delete those viadelete object.name
, and if you'rebind()
ing events you can alwaysunbind()
them.