问题
InnerHTML with special character is trimming the data.
elem.innerHTML = displayedObjects.name;
here the displayedObjects.name contains a string like Test&string. The above statement is assigning the value only Test,
What could be done here?
回答1:
That's because Test&string isn't actually valid HTML, because & is an escape character for an HTML entity. If it were properly encoded, it would be Test&string instead.
If you're just trying to set the text of an element, I'd suggest you use innerText instead:
elem.innerText = displayedObjects.name;
来源:https://stackoverflow.com/questions/20604572/innerhtml-with-special-character-is-trimming-the-data