额,又来了,再求一个清除所有标签所有属性的的JS 正则表达式^^

问题描述

额,又来了,再求一个清除所有标签所有属性的的JS 正则表达式^^比如<p style="border:1px;">呵呵</p> <span id="row">第一行</span>等,清除完后只要<p>呵呵</p> <span>第一行</span> 这样就可以了,

解决方案

应该满足你的要求了。<!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> <title></title><script type="text/javascript">window.onload = function() { document.body.innerHTML = document.body.innerHTML.replace(/<([a-zA-Z1-6]+)(s*[^>]*)?>/g, "<$1>"); };</script> </head> <body> <p style="border:1px;">haha</p> <span id="row">hehe</span> </body> </html>
解决方案二:
<!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> <title></title></head><body><p class="p1">asdfaspf</p><p class="p2">asdpfasf</p><script type="text/javascript">document.onclick = function(){var body = document.getElementsByTagName('body')[0];body.innerHTML = body.innerHTML.replace(/<([a-z]+) [^>]*>/ig, "<$1>");} </script></body></html>

时间: 2024-09-19 09:20:20