jquery find() 和 remove() 脚本标签不起作用

jquery find() and remove() with script tag not working

本文关键字:标签 不起作用 脚本 find jquery remove      更新时间:2023-09-26

>我有以下脚本,可以从给定字符串中成功删除标签。但现在的问题是,如果我不尝试删除脚本标签,下面的 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,它正在相应地工作。

试试这个:

function fun(x)
{
  alert(x);
  var html = x.bold();       
  html=$(html);
  html.find('p').remove();
  return($(html).html());
} 

http://jsfiddle.net/FArbJ/2/

相关文章: