日期:2014-05-16 浏览次数:20368 次
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script> </head> <body> <div> <p>test1</p> <p>test2</p> </div> <script type="text/javascript"> var txt = $("div p").text(); $("div").html(txt); </script> </body> </html>
------解决方案--------------------
replaceWith(content)将所有匹配的元素替换成指定的HTML或DOM元素。
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <TITLE> New Document </TITLE> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <META NAME="Author" CONTENT=""> <META NAME="Keywords" CONTENT=""> <META NAME="Description" CONTENT=""> <style type="text/css"> </style> <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> </HEAD> <BODY> <p>你在他乡还好吗</p><p>灭烛怜光满!!</p> </BODY> </HTML>
------解决方案--------------------
$("div:has(p)").remove();
//or
$(obj).is("p")..