如何删除.getScript()加载的脚本 [英] How to delete script loaded by .getScript()

查看:92
本文介绍了如何删除.getScript()加载的脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我用 .getScript('file.js')加载脚本时,有没有办法在以后删除该脚本?有点像干净,我说删除我之前加载的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

推荐答案

getScript 在保持脚本的意义上不会加载脚本;它从服务器下载脚本并立即运行。所以没有必要删除它。

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.

但是,脚本创建的任何DOM对象或它定义的函数等都将继续存在。删除这些将需要具体了解它们是什么;最好的办法是让你的脚本定义一个函数,删除脚本其余部分创建的所有内容。

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.

这篇关于如何删除.getScript()加载的脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆