zoukankan      html  css  js  c++  java
  • markdown编辑器实现笔记

    1.js代码放在head和body的区别

    <html>
    <head>
      <script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.1.8/ace.js" type="text/javascript" charset="utf-8"></script>
      <script type="text/javascript" src="./js/jquery/jquery.min.js"></script>
      <script>
        var templateEditor = document.getElementById("templateEditor");
        templateEditor.innerHTML="hello world";
      </script>
    </head>
    
    <body>
       <div id='templateEditor' style='height:500px;'></div>
    </body>
    </html>
    
    

    js代码如果放在head,则先于body定义,如果代码里要对body的元素进行修改,这时body的元素还没有定义,则会出现undefined错误。
    正确的写法应该是:

    <body>
       <div id='templateEditor' style='height:500px;'></div>
       <script>
         var templateEditor = document.getElementById("templateEditor");
         templateEditor.innerHTML="hello world";
       </script>
    </body>
    

    即定义之后执行。
    或者用jquery修改

      <script>
        $(document).ready(function() {
            $("#templateEditor").html("hello world");
        });
      </script>
    
  • 相关阅读:
    线性反馈系统
    静磁场
    平面波的传播
    Partition does not end on cylinder boundary
    FFTW简介及使用
    EINTR、ERESTARTSYS和SIGINT
    凉面
    linux Shell编程
    Linux From Scratch [2]
    Linux From Scratch [1]
  • 原文地址:https://www.cnblogs.com/wacc/p/4991520.html
Copyright © 2011-2022 走看看