例如有这样一段html代码:
phpstudy演示代码
<p>大家好,欢迎来到phpstudy.net</p>
这里为大家提供最优秀的<a href=\"http://www.phpstudy.net/js\">js</a>代码和教程
我们希望删除这段html代码里面的一对<p>标签,但是要保持里面的内容不被删除,这里我们用jquery处理,详细的jQuery代码:
<script type=\"text/javascript\" src=\'http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js\'></script>
<script type=\"text/javascript\">
$(function(){
$(\"p\").each(function(){
var xx=$(this).html();
$(this).replaceWith(xx);
})
})
</script>
这里通过jquery的html方法和replaceWith方法对p标签进行遍历替换
本文地址:https://www.stayed.cn/item/5877
转载请注明出处。
本站部分内容来源于网络,如侵犯到您的权益,请 联系我