Why are my “
” tags getting converted to “
”?

后端 未结 5 2120
Happy的楠姐
Happy的楠姐 2020-12-31 16:05

I have HTML data stored in database which I wish to display as is. It keeps converting
tags to <br /> which is a behavior I do not want. I

相关标签:
5条回答
  • 2020-12-31 16:07

    &lt;br /&gt; == <br /> You just need to Decode the output to get back the original HTML.

    Use javascript unescape function

    0 讨论(0)
  • 2020-12-31 16:13

    Your problem is with

    $("#venueaddress").text(venueaddress2);
    

    you should use

    $("#venueaddress").html(venueaddress2);
    

    Text will encode any html character and will display it in span as encoded, html will not.

    0 讨论(0)
  • 2020-12-31 16:18

    You can also replace the chars with the actual <br/> tag.

    myString.replace(/&lt;br&gt;/g, '<br/>')
    
    0 讨论(0)
  • 2020-12-31 16:30

    Your html data is being "escaped." This prevents people from sending the <script> tag to unsuspecting people at their browser.

    Fix: first you'll need to determine if your issue is a "bug" or a "feature."

    Escaping html is usually a good thing. Especially if the only issue is one of presentation.

    For example, a work around might be to insert newline characters rather than the br element.

    0 讨论(0)
  • 2020-12-31 16:34

    Presumably because when you are inserting it into the DOM, you are inserting it as text and not as HTML.

    Since you haven't show the code you are using to do that, it is hard to say for sure, or to say what the best way to change it so it expects HTML would be.

    0 讨论(0)
提交回复
热议问题