<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获得的内容转义?代码是什么的详细内容。
