溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

jquery中常用的事件是什么

發(fā)布時(shí)間:2023-01-04 09:33:06 來(lái)源:億速云 閱讀:82 作者:iii 欄目:web開(kāi)發(fā)

這篇文章主要介紹“jquery中常用的事件是什么”的相關(guān)知識(shí),小編通過(guò)實(shí)際案例向大家展示操作過(guò)程,操作方法簡(jiǎn)單快捷,實(shí)用性強(qiáng),希望這篇“jquery中常用的事件是什么”文章能幫助大家解決問(wèn)題。

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

一、jQuery事件的分類(lèi)

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

1、基礎(chǔ)事件

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

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中常用的事件是什么

三、鍵盤(pán)事件

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

jquery中常用的事件是什么

四、表單事件

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

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

jquery中常用的事件是什么

五、綜合示例

jquery中常用的事件是什么

需求說(shuō)明:

  • 1、用戶名輸入框獲得焦點(diǎn)時(shí)輸入框背景色為淺藍(lán)色,失去焦點(diǎn)時(shí)還原為白色背景色。

  • 2、鼠標(biāo)移至登錄按鈕時(shí)字體變粗,移出時(shí)整體恢復(fù)正常。

  • 3、敲擊鍵盤(pán)的“回車(chē)”鍵時(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");
            });

            // 鍵盤(pán)事件,敲擊回車(chē)鍵進(jìn)行表單提交,keyCode的數(shù)值代表不同的鍵盤(pán)按鍵
            // js需要區(qū)分keyCode(IE)和which(FF)的兼容性,event.keyCode||event.which用來(lái)考慮兼容性
            $(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>

效果:

jquery中常用的事件是什么

關(guān)于“jquery中常用的事件是什么”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識(shí),可以關(guān)注億速云行業(yè)資訊頻道,小編每天都會(huì)為大家更新不同的知識(shí)點(diǎn)。

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI