登录事件,鼠标点击输入框隐藏默认值事件 - 军军小站|张军博客 HTML:12地址:3

登录事件,鼠标点击输入框隐藏默认值事件

系统 2106 0

CSS:

      
        1
      
      
        <style>


      
      
        2
      
      
            #txt1,#txt2
      
      {
      
         color
      
      :
      
        #CCC
      
      ;
      
         border
      
      :
      
        1px solid #666
      
      ;}


      
        3
      
      
            #pswd
      
      {
      
         display
      
      :
      
        none
      
      ;
      
        border
      
      :
      
        1px solid #666
      
      ;}


      
        4
      
      
        </style>        
      
    

引用JS库:

      
        1
      
       <script src="http://libs.baidu.com/jquery/1.7.2/jquery.min.js"></script>
    

HTML:

      
         1
      
      
        <
      
      
        form 
      
      
        id
      
      
        ="myform"
      
      
         action
      
      
        ="#"
      
      
        >
      
      
         2
      
      
            地址:


      
      
         3
      
      
        <
      
      
        input 
      
      
        type
      
      
        ="text"
      
      
         id
      
      
        ="txt1"
      
      
         value
      
      
        ="请输入邮箱地址"
      
      
        />
      
      
         4
      
      
         5
      
      
        <
      
      
        br 
      
      
        />
      
      
         6
      
      
        <
      
      
        br 
      
      
        />
      
      
         密码:


      
      
         7
      
      
        <
      
      
        input 
      
      
        type
      
      
        ="text"
      
      
         id
      
      
        ="txt2"
      
      
         value
      
      
        ="请输入邮箱密码"
      
      
        />
      
      
         8
      
      
        <
      
      
        input 
      
      
        type
      
      
        ="password"
      
      
         id
      
      
        ="pswd"
      
      
        />
      
      
         9
      
      
        10
      
      
        <
      
      
        br 
      
      
        />
      
      
        11
      
      
        <
      
      
        br 
      
      
        />
      
      
        12
      
      
        <
      
      
        input 
      
      
        type
      
      
        ="button"
      
      
         id
      
      
        ="btn"
      
      
         value
      
      
        ="登陆"
      
      
        />
      
      
        13
      
      
        </
      
      
        form
      
      
        >
      
    

JS代码:

      
         1
      
      
        <
      
      
        script 
      
      
        type
      
      
        ="text/javascript"
      
      
         charset
      
      
        ="utf-8"
      
      
        >
      
      
         2
      
      
        dlsj(
      
      
        '
      
      
        #txt1
      
      
        '
      
      
        ,
      
      
        '
      
      
        请输入邮箱地址
      
      
        '
      
      
        ,
      
      
        '
      
      
        #txt2
      
      
        '
      
      
        ,
      
      
        '
      
      
        #pswd
      
      
        '
      
      
        )   
      
      
        //
      
      
        调用
      
      
         3
      
      
         4
      
      
         5
      
      
        function
      
      
         dlsj (txt1,txt1_val,txt2,password) {


      
      
         6
      
      
        //
      
      
        邮箱地址输入框获取焦点
      
      
         7
      
      
                $(txt1).focus(
      
      
        function
      
      
        (){


      
      
         8
      
      
        var
      
      
         txt1_value
      
      
        =
      
      
        $(txt1).val();


      
      
         9
      
      
        if
      
      
        (txt1_value
      
      
        ==
      
      
        txt1_val){


      
      
        10
      
      
                $(
      
      
        this
      
      
        ).val(
      
      
        ''
      
      
        );


      
      
        11
      
      
                }


      
      
        12
      
      
            })


      
      
        13
      
      
        14
      
      
        //
      
      
        邮箱地址输入框失去焦点
      
      
        15
      
      
            $(txt1).blur(
      
      
        function
      
      
        (){


      
      
        16
      
      
        var
      
      
         txt1_value
      
      
        =
      
      
        $(txt1).val();


      
      
        17
      
      
        if
      
      
        (txt1_value
      
      
        ==
      
      
        ""
      
      
        )


      
      
        18
      
      
                $(
      
      
        this
      
      
        ).val(txt1_val);{


      
      
        19
      
      
                }


      
      
        20
      
      
            })


      
      
        21
      
      
        var
      
      
         $txt2_obj
      
      
        =
      
      
        $(txt2);
      
      
        //
      
      
        获取id为txt2的jquery对象
      
      
        22
      
      
        var
      
      
         $pswd_obj
      
      
        =
      
      
        $(password);
      
      
        //
      
      
        获取id为txt2的jquery对象
      
      
        23
      
      
            $txt2_obj.focus(
      
      
        function
      
      
        (){


      
      
        24
      
      
                $pswd_obj.show().focus();
      
      
        //
      
      
        使密码输入框获取焦点
      
      
        25
      
      
                $txt2_obj.hide();
      
      
        //
      
      
        隐藏文本输入框
      
      
        26
      
      
        27
      
      
           })


      
      
        28
      
      
            $pswd_obj.blur(
      
      
        function
      
      
        (){


      
      
        29
      
      
        if
      
      
        ($pswd_obj.val()
      
      
        ==
      
      
        ''
      
      
        ){
      
      
        //
      
      
        密码输入框失去焦点后,若输入框中没有输入字符时,则显现文本输入框
      
      
        30
      
      
                 $txt2_obj.show();


      
      
        31
      
      
                 $pswd_obj.hide();


      
      
        32
      
      
                 }


      
      
        33
      
      
        34
      
      
            })


      
      
        35
      
      
        }    


      
      
        36
      
      
        </
      
      
        script
      
      
        >
      
    

 

登录事件,鼠标点击输入框隐藏默认值事件


更多文章、技术交流、商务合作、联系博主

微信扫码或搜索:z360901061

微信扫一扫加我为好友

QQ号联系: 360901061

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描下面二维码支持博主2元、5元、10元、20元等您想捐的金额吧,狠狠点击下面给点支持吧,站长非常感激您!手机微信长按不能支付解决办法:请将微信支付二维码保存到相册,切换到微信,然后点击微信右上角扫一扫功能,选择支付二维码完成支付。

【本文对您有帮助就好】

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描上面二维码支持博主2元、5元、10元、自定义金额等您想捐的金额吧,站长会非常 感谢您的哦!!!

发表我的评论
最新评论 总共0条评论