js只删除标签不删除内容?
发布网友
发布时间:2022-04-30 19:09
我来回答
共1个回答
热心网友
时间:2022-06-30 03:30
<body>
<div style="width:100px; height:100px; border:1px solid #ccc;">
</div>
</body>
<script>
var oDiv = document.getElementsByTagName('div')[0];
var oDiv2 = document.createElement('div');
oDiv2.innerHTML='12312312323234234<span>2134234434534</span>23423425';
oDiv2.innerHTML=oDiv2.innerHTML.replace(/<\/?span>/g,'');
oDiv.appendChild(oDiv2);
alert(oDiv2.innerHTML); //'12312312323234234213423443453423423425'
</script>
如果有问题,可以追问