[英]How to remove dynamically added jquery
I am working with C# and i am loading a jquery file 1.8.1 in the layout, but there is a module pulling through which is adding another jquery file 1.6.1 is there any way for me to remove it without physically going in and remove it so i need to remove it dynamically. 我正在使用C#,并且正在布局中加载一个jquery文件1.8.1,但是有一个模块可以通过它添加另一个jquery文件1.6.1,我有什么办法可以删除它而无需实际进入和删除所以我需要动态删除它。
Thanks. 谢谢。
use follwing function and pass filename you want to remove 使用以下功能并传递要删除的文件名
function removeScript(filename){
var allsuspects=document.getElementsByTagName('script')
for (var i=allsuspects.length; i>=0; i--){ //search backwards within nodelist for matching elements to remove
if (allsuspects[i] && allsuspects[i].getAttribute('src')!=null && allsuspects[i].getAttribute('src').indexOf(filename)!=-1)
allsuspects[i].parentNode.removeChild(allsuspects[i]) //remove element by calling parentNode.removeChild()
}
}
尝试使用此代码段动态删除script
文件。
$("script[src='jquery-1.6.1.js']").remove()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.