1

我有以下脚本可以从给定的字符串中成功删除标签。但现在的问题是,如果我不尝试删除脚本标签,下面的 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>'))">
4

2 回答 2

1

Actually you will work, the problem I guess is that your jQuery is not added properly.

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

Here is a JSFiddle which is working accordingly.

于 2013-11-06T07:22:39.130 回答
0

尝试这个:

function fun(x)
{
  alert(x);

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

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

于 2013-11-06T07:50:08.393 回答