js 各種事件 如:點擊事件、失去焦點、鍵盤事件等


事件驅動:
        我們點擊按鈕 按鈕去掉用相應的方法。
        
        demo:
             <input type="button" value="點擊" onclick="func()">
             function func(){
                     alert(1);
                   
                   }
        事件:
            onclick 點擊
            onblur:失去焦點
            onfocus  得到焦點
            
            
            onkeydown 按下鍵盤
            onkeyup   松開鍵盤
            onkepress  按住鍵盤
            
            
            onmousedown 按下鼠標
            onmouseup  松開鼠標
            onmouseover 把鼠標放到上面
            ommousemove 移動鼠標
            onmouseout  移開鼠標
            
            
            onload  :頁面加載
            onchange:改變
            onsubmit  :表單提交。
            
    如何綁定事件:

        (1)<input type="button" value="點擊" onclick="fun()">
                function fun(){
               
                 alert(1);
               
               }
        (2) document.getElementById("bt").onclick=function(){
         
                     alert(2);
                 
                 }       
                    
        (3) onload頁面加載
                 window.onload=function(){/*  頁面加載完了以后 在執行onload里面的方法  */}
                 
                  
    失去焦點得到焦點小案例
        
      <input type="text" id="te" onblur="fun();"/><br/>
      <input type="text" id="xt"  onfocus="func()" size="50"/>
    
      function fun(){
           /* 失去焦點  */
           var vas = document.getElementById("te").value;
       
           alert(vas);
       
       }
       
       function func(){
          /* 得到焦點 */
          var da = new Date();
          document.getElementById("xt").value=da.toLocaleString();
       }


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM