Dynamically changing the HTML of a div with jQuery is causing HTML encoding to be lost

后端 未结 4 1775
栀梦
栀梦 2021-01-28 14:20

I have a piece of code which dynamically alters the HTML of a div called \'accordion\' on the fly like so:

// htmlstring contains some HTML containing some HTML          


        
4条回答
  •  故里飘歌
    2021-01-28 14:53

    Check this link: HTML-encoding lost when attribute read from input field

    you can use the function that Anentropic write.

    function htmlEscape(str) {
        return String(str)
                .replace(/&/g, '&')
                .replace(/"/g, '"')
                .replace(/'/g, ''')
                .replace(//g, '>');
    }
    

提交回复
热议问题