亚洲最大看欧美片,亚洲图揄拍自拍另类图片,欧美精品v国产精品v呦,日本在线精品视频免费

  • 站長(zhǎng)資訊網(wǎng)
    最全最豐富的資訊網(wǎng)站

    jquery中常用的事件有哪些

    jquery中常用的事件有:1、window事件;2、鼠標(biāo)事件,是當(dāng)用戶在文檔上面移動(dòng)或單擊鼠標(biāo)時(shí)而產(chǎn)生的事件,包括鼠標(biāo)單擊、移入事件、移出事件等;3、鍵盤事件,是用戶每次按下或者釋放鍵盤上的按鍵時(shí)都會(huì)產(chǎn)生事件,包括按下按鍵事件、釋放按鍵按鍵等;4、表單事件,例如當(dāng)元素獲得焦點(diǎn)時(shí)會(huì)觸發(fā)focus()事件,失去焦點(diǎn)時(shí)會(huì)觸發(fā)blur()事件,表單提交時(shí)會(huì)觸發(fā)submit()事件。

    jquery中常用的事件有哪些

    本教程操作環(huán)境:windows7系統(tǒng)、jquery3.6版本、Dell G3電腦。

    一、jQuery事件的分類

    jQuery事件是對(duì)JavaScript事件的封裝,常用事件分類如下:

    1、基礎(chǔ)事件

    window事件。鼠標(biāo)事件。鍵盤事件。表單事件。

    2、復(fù)合事件是多個(gè)事件的組合

    鼠標(biāo)光標(biāo)懸停。鼠標(biāo)連續(xù)點(diǎn)擊。

    二、鼠標(biāo)事件

    鼠標(biāo)事件是當(dāng)用戶在文檔上面移動(dòng)或單擊鼠標(biāo)時(shí)而產(chǎn)生的事件,常用鼠標(biāo)事件有:

    jquery中常用的事件有哪些

    三、鍵盤事件

    用戶每次按下或者釋放鍵盤上的按鍵時(shí)都會(huì)產(chǎn)生事件,常用鍵盤事件如下:

    jquery中常用的事件有哪些

    四、表單事件

    當(dāng)元素獲得焦點(diǎn)時(shí),會(huì)觸發(fā)focus()事件,失去焦點(diǎn)時(shí),會(huì)觸發(fā)blur()事件。

    表單提交時(shí)會(huì)觸發(fā)submit()事件。

    jquery中常用的事件有哪些

    五、綜合示例

    jquery中常用的事件有哪些

    需求說明:

    • 1、用戶名輸入框獲得焦點(diǎn)時(shí)輸入框背景色為淺藍(lán)色,失去焦點(diǎn)時(shí)還原為白色背景色。
    • 2、鼠標(biāo)移至登錄按鈕時(shí)字體變粗,移出時(shí)整體恢復(fù)正常。
    • 3、敲擊鍵盤的“回車”鍵時(shí)觸發(fā)表單提交事件。

    代碼:

    <!DOCTYPE html> <html lang="en"> <head>     <meta charset="UTF-8">     <meta name="viewport" content="width=device-width, initial-scale=1.0">     <meta http-equiv="X-UA-Compatible" content="ie=edge">     <title>事件演示示例</title>     <style type="text/css">         #login{             width: 400px;             height: 250px;             background-color: #f2f2f2;             border:1px solid #DDDDDD;             padding: 5px;         }         #login fieldset {             border: none;             margin-top: 10px;         }         #login fieldset legend{             font-weight: bold;         }         #login fieldset p{             display: block;             height: 30px;         }         #login fieldset p label {             display: block;             float:left;             text-align: right;             font-size: 12px;             width: 90px;             height: 30px;             line-height: 30px;         }         #login fieldset p input {             display: block;             float:left;             border: 1px solid #999;             width: 250px;             height: 30px;             line-height: 30px;         }         #login fieldset p input.code{             width: 60px;         }         #login fieldset p img{             margin-left: 10px;         }         #login fieldset p a{             color: #057BD2;             font-size: 12px;             text-decoration: none;             margin: 10px;         }         #login fieldset p input.btn{             background: url("./images/login.gif") no-repeat;             width: 98px;             height: 32px;             margin-left: 60px;             color: #ffffff;             cursor: pointer;         }         #login fieldset p input.input_focus{             background-color: #BEE7FC;         }         </style>        <!--引入jQuery-->        <script src="../jquery-3.3.1.js"></script>        <!--javascript-->        <script>          $(function(){              // 用戶名輸入框的焦點(diǎn)事件              $("input[name='member']").focus(function(){                  $(this).addClass("input_focus");              });              // 用戶名失去焦點(diǎn)              $("input[name='member']").blur(function(){                  $(this).removeClass("input_focus");              });               // 鼠標(biāo)移入移出事件              $(".btn").mouseover(function(){                  $(this).css("font-weight","bold");              });              $(".btn").mouseout(function(){                  $(this).css("font-weight","normal");              });               // 鍵盤事件,敲擊回車鍵進(jìn)行表單提交,keyCode的數(shù)值代表不同的鍵盤按鍵              // js需要區(qū)分keyCode(IE)和which(FF)的兼容性,event.keyCode||event.which用來考慮兼容性              $(document).keypress(function(e){                  if(e.keyCode==13){                      //$("#login").submit();                      // 模擬表單提交                      alert("觸發(fā)表單的提交事件");                  }              });          });        </script> </head> <body>     <form id="login">         <fieldset>           <legend>用戶登錄</legend>           <p>               <label>用戶名:</label>               <input name="member" type="text" />           </p>           <p>               <label>密碼:</label>               <input name="password" type="text" />           </p>           <p>               <label>驗(yàn)證碼:</label>               <input name="code" type="text" class="code" />               <img src="images/code.gif" width="80" height="30" /><a href="#" rel="external nofollow"  rel="external nofollow"  rel="external nofollow" >換一張</a>           </p>           <p>               <input name="" type="button" class="btn" value="登錄" />               <a href="#" rel="external nofollow"  rel="external nofollow"  rel="external nofollow" >注冊(cè)</a><span>|</span><a href="#" rel="external nofollow"  rel="external nofollow"  rel="external nofollow" >忘記密碼?</a>           </p>         </fieldset>       </form> </body> </html>
    登錄后復(fù)制

    效果:

    jquery中常用的事件有哪些

    【推薦學(xué)習(xí):jQuery視頻教程、web前端視頻】

    贊(0)
    分享到: 更多 (0)
    網(wǎng)站地圖   滬ICP備18035694號(hào)-2    滬公網(wǎng)安備31011702889846號(hào)