0

p当我单击此标签时,有谁知道如何从我的 html 页面中删除“js/sample.js”文件:

 <!DOCTYPE html>
 <html>
 <head>
<style>
p { color:red; margin:5px; cursor:pointer; }
</style>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="js/sample.js"></script>
</head>
 <body>
<p>First Paragraph</p>
 <p>Second Paragraph</p>
 <p>Yet one more Paragraph</p>

<script>
$("p").click(function () {
$(' ').removeattr('src');

 });
 </script>
</body>
 </html>
4

3 回答 3

5

亲爱的朋友试试下面的代码它会为你工作

<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script id="script1" src="js/sample.js"></script>

<script>
    $(function () {

        $("p").click(function () {
            $('script1').att('src').remove();
        });
    });
</script>
于 2013-04-29T17:17:18.493 回答
2

有趣...您可以在脚本标签中添加一个类,然后在 click 函数中添加类似的内容:

$('.myClass').remove();
于 2013-04-29T17:04:06.763 回答
0

您可以删除脚本标签

$('script[src="js/sample.js"]').remove();

但是,一旦脚本执行完毕,简单地删除该标签不会“撤消”脚本。您实际上需要销毁您的 sample.js 脚本创建的任何变量/方法。

于 2013-04-29T17:08:52.567 回答