html字符串转换成纯文字

Posted on   猫头唔食鱼  阅读(277)  评论(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
复制代码

 

努力加载评论中...
点击右上角即可分享
微信分享提示