Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/385.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用jQuery删除脚本_Javascript_Jquery_Jquery Plugins_Jquery Events - Fatal编程技术网

Javascript 使用jQuery删除脚本

Javascript 使用jQuery删除脚本,javascript,jquery,jquery-plugins,jquery-events,Javascript,Jquery,Jquery Plugins,Jquery Events,我的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-

我的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>
我的jQuery:

 var stringOfHtml = '<script type="text/javascript" src="http://firstScript.com"></script>';
 var html = $(stringOfHtml);
 html.find('script').remove();
我想删除包含的脚本http://firsttScript.com,但不起作用。是否可以删除此脚本并在之后添加?因为我需要刷新此脚本,所以只需要更改

    var html = $(stringOfHtml);
    html.remove();
假设标记实际位于HTMLDOM中,并且包含jQuery引用

您可以使用.filter获取src为'http://firstScript.com“还有这个。移开

而且


这是不允许的,并且会引发错误意外令牌非法

您可以将其指定为以下代码:

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

   $(document).ready(function(){
     $('.right-bloc-pub-1').find('script[src="http://firstScript.com"]').remove();
   });


要选择并删除第一个脚本,可以这样做:$'script[src=http://firstScript.com]“.删除

只需知道,这将从DOM中删除脚本,但不会删除此脚本中加载的库。例如,如果第一个脚本加载jQuery,$变量仍将包含jQuery。要完全删除jQuery,可以添加$=undefined;jQuery=未定义


试试这个

在您的实际html中存在吗?或者只是一个变量?更好的解决方案:$'right-bloc'。find'script[src=http://firstScript.com]“。删除。是否可以在删除此脚本后添加?因为我需要刷新脚本要再次添加脚本,如果要刷新脚本,可以这样做:$'.right-bloc-pub-1'。append我建议您在此处使用id属性,而不是类,假设它是唯一的。
html.find('script[src="http://firstScript.com"]').remove();
   $(document).ready(function(){
     $('.right-bloc-pub-1').find('script[src="http://firstScript.com"]').remove();
   });
$(document).ready(function(){
   $('.right-bloc-pub-1').find('script').attr('src', 'http://firstScript.com').remove();
});
$(document).ready(function(){
      $('.right-bloc-pub-1').html().remove();
});