jQuery文字框中的事件應用

來源:互聯網
上載者:User

標籤:float   javascrip   bsp   丟失   ffd   oct   xhtml 1.0   order   input   

jQuery文字框中的事件應用<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head>    <title>jquery文字框中的事件應用</title>    <style type="text/css">    body{ font-size:13px;}    /*元素初始化樣式*/    .divInit{ width:390px; height:55px; line-height:55px; padding-left:20px;}    .txtInit{ border:solid 1px #666; padding:3px; background-image:url(‘Images/bg_email_input.gif‘);}    .spnInit{ width:179px; height:40px; line-height:40px; float:right; margin-top:8px; padding-left:10px; background-repeat:no-repeat;}    /*元素丟失焦點樣式*/    .divBlur{ background-color:#FEEEC2;}    .txtBlur{ border:solid 1px #666; padding:3px; background-image:url(‘Images/bg_email_input2.gif‘);}    .spnBlur{ background-image:url(‘Images/bg_email_wrong.gif‘);}    .divFocu{ background-color:#EDFFD5;} /*div擷取焦點樣式*/    .spnSucc{ background-image:url(‘Images/pic_Email_ok.gif‘); margin-top:20px;} /*驗證成功時span樣式*/    </style>    <script src="Scripts/jquery-1.4.1-vsdoc.js" type="text/javascript"></script>    <script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>    <script type="text/javascript">        $(function () {            $("#txtEmail").trigger("focus"); //預設時文字框獲得焦點            $("#txtEmail").focus(function () { //文字框擷取焦時間點事件                $(this).removeClass("txtBlur").addClass("txtInit");                $("#email").removeClass("divBlur").addClass("divFocu");                $("#spnTip").removeClass("spnBlur").removeClass("spnSucc").html("請輸入您常用郵箱地址!");            });            $("#txtEmail").blur(function () { //文字框丟失焦時間點事件                var vTxt = $("#txtEmail").val();                if (vTxt.length == 0) { //文字框中是否輸入了郵箱                    $(this).removeClass("txtInit").addClass("txtBlur");                    $("# email").removeClass("divFocu").addClass("divBlur");                    $("#spnTip").addClass("spnBlur").html("郵箱地址不可為空!");                }                else { //檢測郵箱格式是否正確                    if (!chkEmail(vTxt)) { //如果不正確                        $(this).removeClass("txtInit").addClass("txtBlur");                        $("#email").removeClass("divFocu").addClass("divBlur");                        $("#spnTip").addClass("spnBlur").html("郵箱格式不正確!");                    }                    else { //如果正確                        $(this).removeClass("txtBlur").addClass("txtInit");                        $("#email").removeClass("divFocu");                        $("#spnTip").removeClass("spnBlur").addClass("spnSucc").html("");                    }                }            });            /*驗證郵箱格式是否正確 參數strEmail,需要驗證的郵箱*/            function chkEmail(strEmail) {                var vChk = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;                if (!vChk.test(strEmail)) {                    return false;                }                else {                    return true;                }            }        });    </script></head><body><form id="form1" action="#">    <div id="email" class="divInit">郵箱:        <span id="spnTip" class="spnInit"></span>        <input type="text" id="txtEmail" class="txtInit" />    </div></form></body></html>

 

jQuery文字框中的事件應用

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.