转载自:
http://www.sharejs.com/jquery/article/10019
我们希望删除这段html代码里面的一对<p>标签,但是要保持里面的内容不被删除,本文提供的这个jquery方法就可以简单实现。
有这样一段html代码:
脚本分享网演示代码
<p>大家好,欢迎来到sharejs.com</p>
这里为大家提供最优秀的<a href="http://www.sharejs.com/js">js</a>代码和教程
我们希望删除这段html代码里面的一对<p>标签,但是要保持里面的内容不被删除,通过前段
js
脚本是可以实现的,这里我们用
jquery
处理更为简单,详细的js代码如下:
<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标签进行遍历替换
jQuery
使用下面两个方法来
删除
或是清空某个
HTML
元素。
remove() –
删除
指定
的元素(包括其子元素) empty() – 清空
指定
元素的子元素
<!DOCTYPE
html
>
<
html
>
<head>
<meta charset="utf-8">
<...
浏览器打开
function repalce
Html
(str){
var dd=str.replace(//g,"");
var dds=dd.replace(/ /g,"");//dds为得到后的
内
容
return dds;
浏览器打开
先把要
删除
的
标签
内
容复制出来,然后在该节点前插入进去,最后
删除
该节点
var
html
= $('mark[data-id="123"]').
html
();
$('mark[data-id="123"]').before(
html
);
$('mark[data-id="123"]').remove();...
浏览器打开
function temp(msg) {
var msgTemp = msg.replace(//ig, '');//
删除
全部
html
标签
及其属性, 但
保留
标签
内
容
var msgTemp2 = msg.replace(/()|()/g, '')
浏览器打开
input
标签
的 type 属性详解1. input 输入
标签
的type 属性1.1 input
标签
的 type类型 属性的常用属性值⑴ type="text"⑵ type="button"⑶ type="checkbox"⑷ type="file"⑸ type="hidden"⑹ type="image"⑺ type="password"⑻ type="radio"⑼ type="rese...
浏览器打开