zoukankan      html  css  js  c++  java
  • JavaScript中innerText和innerHTML的区别

    案例

    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
      <script type="text/javascript">
        onload=function(){
         //把所有内容全部设置到层中。
         document.getElementById('btn1').onclick=function(){
               document.getElementById('dv').innerText='<h1>标题</h1>';
         };
            //把效果直接显示出来
         document.getElementById('btn2').onclick=function(){
               document.getElementById('dv').innerHTML='<h1>标题</h1>';
         };
            //只获取文字内容
         document.getElementById('btn3').onclick=function(){
          alert( document.getElementById('dv').innerText);
         };
            //获取该效果的所有标签和文本
         document.getElementById('btn4').onclick=function(){
          alert( document.getElementById('dv').innerHTML);
         };           
        };
      </script>
    </head>
    <body>
    <div id="dv">
    </div>
    <input type="button" id="btn1" value="设置innerText"/>
    <input type="button" id="btn2" value="设置innerHtml"/>
    <input type="button" id="btn3" value="获取innerText"/>
    <input type="button" id="btn4" value="获取innerHtml"/>
    </body>
    </html>
    clipboard
  • 相关阅读:
    【剑指Offer】6、旋转数组的最小数字
    【剑指Offer】5、用两个栈实现队列
    【剑指Offer】4、重建二叉树
    python面试经典315
    shell面试经典70例
    vim编辑器使用
    bootstrap3基本了解
    Windows Server 2008允许多用户登录远程桌面
    配置远程桌面
    Python-Python及PyCharm的下载与安装
  • 原文地址:https://www.cnblogs.com/mcad/p/4305176.html
Copyright © 2011-2022 走看看