removing html tags from string

前端 未结 3 1097
死守一世寂寞
死守一世寂寞 2021-01-29 07:24

I am trying to remove the HTML tags from a string. Right now I am able to remove the complete HTML tags like for example

dadsasdsad
3条回答
  •  礼貌的吻别
    2021-01-29 07:42

    Using javascript you can do this:

    function removeHTMLTags(htmlString) {
        if(!htmlString) { return; }
        var mydiv = document.createElement("div");
        mydiv.innerHTML = htmlString;
        return mydiv.textContent || mydiv.innerText || '';
    }
    

    [Source]

提交回复
热议问题