本篇文章给大家带来的内容是关于新手如何对innerHTML获得的内容转义?代码是什么,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。
复制代码1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<body>
<div id="code" style="display:none">
var res = a > b ? a: b;
res = res > c ? res : c;
return res;
</div>
</body>
<script>
var txt=document.getElementById("code").innerHTML;
document.write(txt);
// 输出:var res = a > b ? a: b;
// res = res > c ? res : c;
// return res;
//原因是用document.write输出时会对已转义的字符再次转义。
alert(txt);
// 输出:var res = a > b ? a: b;
// res = res > c ? res : c;
// return res;
var str = txt.replace(/>/g,">");
alert(str);
// 输出:var res = a > b ? a: b;
// res = res > c ? res : c;
// return res;
</script>
登录后复制
以上就是对新手如何对innerHTML获得的内容转义?代码是什么的全部介绍,本文内容紧凑,希望大家可以有所收获,更多请关注靠谱客。
以上就是新手如何对innerHTML获得的内容转义?代码是什么的详细内容,更多请关注靠谱客其它相关文章!
最后
以上就是笑点低斑马最近收集整理的关于新手如何对innerHTML获得的内容转义?代码是什么的全部内容,更多相关新手如何对innerHTML获得内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复