我想 从下面的代码中删除.
<div class="country-IN">
<span class="locality">Barnala</span>
<span class="state">Punjab</span>
<span class="country">India</span>
</div>
Run Code Online (Sandbox Code Playgroud)
请帮我摆脱它.
Dav*_*mas 14
我建议:
var el = document.querySelector('.country-IN');
el.innerHTML = el.innerHTML.replace(/ /g,'');
Run Code Online (Sandbox Code Playgroud)
或者,使用jQuery:
$('.country-IN').html(function(i,h){
return h.replace(/ /g,'');
});
Run Code Online (Sandbox Code Playgroud)
甚至:
$('.country-IN').children().each(function(i,e){
this.parentNode.removeChild(this.nextSibling);
});
Run Code Online (Sandbox Code Playgroud)
虽然简单地编辑HTML文件本身更容易,但只删除那些字符串.