html字符串转换成纯文字

Posted on 2021-02-01 10:05  猫头唔食鱼  阅读(274)  评论(0编辑  收藏  举报
    function HTMLDecode(text) {
            var temp = document.createElement("div");
            temp.innerHTML = text;
            var output = temp.innerText || temp.textContent;
            temp = null;
            return output;
        }


        console.log(HTMLDecode("<div style='color:red'>test</div>"));  // test