新手如何对innerHTML获得的内容转义?代码是什么


本文摘自PHP中文网,作者云罗郡主,侵删。

本篇文章给大家带来的内容是关于新手如何对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 &gt; b ? a: b;

//  res = res &gt; c ? res : c;

//  return res;

var str = txt.replace(/&gt;/g,">");

alert(str);

//  输出:var res = a > b ? a: b;

//  res = res > c ? res : c;

//  return res;

</script>

以上就是对新手如何对innerHTML获得的内容转义?代码是什么的全部介绍,本文内容紧凑,希望大家可以有所收获,更多请关注PHP中文网。

以上就是新手如何对innerHTML获得的内容转义?代码是什么的详细内容,更多文章请关注木庄网络博客

相关阅读 >>

innerhtml与jquery里html()的区别是什么

javascript如何改变文本内容

新手如何对innerhtml获得的内容转义?代码是什么

javascript怎么改变文本内容

js中 value&innerhtml&innertext&textcontent之间的区别对比

innerhtml属性是什么?innerhtml属性的用法

innerhtml和innertext有哪些差异?两者的简单比较

更多相关阅读请进入《innerhtml》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...