如何使用 jQuery 删除脚本

Posted

技术标签:

【中文标题】如何使用 jQuery 删除脚本【英文标题】:How to Remove a script with jQuery 【发布时间】:2021-04-12 20:28:07 【问题描述】:

我的 jQuery 有问题。所以,我想删除一个在 .我的 html 是:

<div id="right-bloc">
        <div class="right-bloc-pub-1">
            <script type="text/javascript" src="http://firstScript.com"></script>
        </div>
        <div class="right-bloc-pub-2">
            <script type="text/javascript" src="http://secondScript.com"></script>
        </div>
</div>

我找到了下面的解决方案

html.find('script[src="http://firstScript.com"]').remove();

但问题是它只删除了只有 HTTP URL 的脚本,因为有些脚本有那种 URL

//ialtears.com/d2/32/42/d23949fadf7b59629f8345.js

我想删除那种网址

【问题讨论】:

【参考方案1】:

你可以这样试试:

JQuery(document).ready(function($)
    $('script').each(function() 
          this.parentNode.removeChild(this);
    );
);

【讨论】:

以上是关于如何使用 jQuery 删除脚本的主要内容,如果未能解决你的问题,请参考以下文章

jQuery 脚本在文本框中显示 NaN,如何删除 NaN? [复制]

如何使用jQuery删除元素内的文本?

如何在我的 Jquery 中删除冲突?

删除不需要的 jQuery 函数

使用jQuery完全删除和替换Div内容

ASP.Net 如何删除自动 jquery 引用?