我将一个变量写入HTML元素,如下所示:
document.getElementById('myDiv').innerHTML = '<xsl:value-of select="@value"/>'; 然而,它的写法如下:
TECHNO A.Ş.这应该是:
TECHNO A.Ş.如何使用Javascript手动获得Unicode字符串的解码版本?
PS:我意识到这个问题发生在Chrome上,但不在Internet上。
发布于 2015-09-21 10:02:15
&#和;are html解析器转义十六进制字符。因此,您需要做的是去掉它们,并将剩余的'15E‘值传递到下面(例如):
<!DOCTYPE html>
<div id="myId">
yo oyyoyoyooy &amp;amp;#xAA;suuupspuspupsu
ssdosudoisduoisudoiud
&amp;#xFE;
</div>
<script>
document.addEventListener("DOMContentLoaded", function(){
var nodeIterator = document.createNodeIterator(
// Node to use as root
document.getElementById('myId'),
// Only consider nodes that are text nodes (nodeType 3)
NodeFilter.SHOW_TEXT,
// Object containing the function to use for the acceptNode method
// of the NodeFilter
{ acceptNode: function(node) {
// Logic to determine whether to accept, reject or skip node
// In this case, only accept nodes that have content
// other than whitespace
if ( /&.*?#x[^;]+;/ig.test(node.data) ) {
return NodeFilter.FILTER_ACCEPT;
}
}
},
false
);
// Show the content of every non-empty text node that is a child of root
var node;
while ((node = nodeIterator.nextNode())) {
node.nodeValue = node.nodeValue.replace(/&.*?#x([^;]+);/ig, function(match, p1) {
return String.fromCharCode(parseInt(p1, 16))
});
}
});
</script>https://stackoverflow.com/questions/32691768
复制相似问题