
例如:
var txt="We are the so-called "Vikings" from the north." document.write(txt) 【错误】
var txt="We are the so-called \"Vikings\" from the north." document.write(txt) 【正确】
例如:<textarea></textarea>之间包含有类似的这种转义字符的时候总会被解析,倒是可以把所有的"&"通过程序替换成"&",但是有些本来就是"&"的也会被转换,这就错了。怎么让<textarea></textarea>之间包含的文本原封不动的显示出来呢?复制代码
代码如下:
<textarea
id="t"
rows="20"cols="20"></textarea>
<script>
document.getElementById('t').innerText='a<&>'
</script>
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)