gpt4 book ai didi

javascript - 带有脚本标签的jquery find() 和remove() 不起作用

转载 作者:行者123 更新时间:2023-11-28 01:50:00 26 4
gpt4 key购买 nike

我有以下脚本,可以成功地从给定字符串中删除标签。但现在的问题是,如果我不尝试删除脚本标签,下面的 fun() 函数会自动删除脚本标签。有人可以尝试向我解释一下吗?

<script src="jquery-1.8.3.js"></script>
<script>
function fun(x)
{
alert(x);

var html = $(x.bold());
html.find('p').remove();
return html.html();

//alert(html);

}
</script>
<input type="button" value="click" onclick="alert(fun('<script>hello script</script><p>hello p</p><div>hello div</div>'))">

最佳答案

实际上你会工作的,我猜问题是你的 jQuery 没有正确添加。

<script src="jquery-1.8.3.js"></script>  <!-- jQuery Lib is not added properly-->

这是一个JSFiddle这是相应的工作。

关于javascript - 带有脚本标签的jquery find() 和remove() 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19806199/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com