因为这仍然是一个公认的答案,尽管是一个非常hacky的解决方案,我将Gabi的代码融入其中,留下我自己作为一个坏榜样。
var html = document.getElementById("txt").innerHTML;
document.getElementById("txt").innerHTML = html.replace(/<[^>]*>/g, "");}// Gabi's elegant approach, but eliminating one unnecessary line of code:function gabi_content() {
var element = document.getElementById('txt');
element.innerHTML = element.innerText || element.textContent;}// and exploiting the fact that IDs pollute the window namespace:function txt_content() {
txt.innerHTML = txt.innerText || txt.textContent;}
I amworking in ABC company.