日期:2014-05-16 浏览次数:20350 次
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>NewDocument</title> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <meta name="generator" content="Editplus" /> <meta name="author" content="" /> <meta name="keywords" content="" /> <meta name="description" content="" /> </head> <body> <div> <p><img src="1.jpg"></p> </div> <script type="text/javascript"> <!-- var imgs = document.getElementsByTagName("img"); for(var i=0,len=imgs.length;i<len;i++){ var node = document.createElement("div"); var img = imgs[i].cloneNode(); node.appendChild(img); imgs[i].parentElement.replaceChild(node,imgs[i]); } //--> </script> </body> </html>
------解决方案--------------------
var pEle = document.getElementsByTagName('p')[0];
var newDom = '<div>' + pEle.innerHTML + '</div>';
pEle.innerHTML = newDom;