javascript-フォーカスイベント(onfocus,onblur)

4935 ワード

javascript-フォーカスイベント(onfocus,onblur)

<html>
    <head>
        <meta charset="utf-8" />
        <title>title>
        <script>

            //      
            function myFocus(){

            }

            //      
            function myBlur(){
                var cont = document.getElementById("cont");
                var str = cont.value;
                var f = document.getElementById("f");


                if(str == "tom"){
                    f.color = "red";
                    f.innerHTML = "        ,    !";
                }else{
                    f.color = "green";
                    f.innerHTML = "√";
                }

            }

            //      
            //    
            function pwdFocus(){
                document.getElementById("img").src = "img/pwd-input.jpg";
            }

            //    
            function pwdBlur(){
                document.getElementById("img").src = "img/user-input.jpg";
            }

        script>
    head>
    <body><input id="cont" type="text" onfocus="myFocus()" onblur="myBlur()"  /><br /><input id="pwd" type="password" onfocus="pwdFocus()" onblur="pwdBlur()" />
        <font id="f" >font>
        <img id="img" src="img/user-input.jpg" />
    body>
html>
実行結果画像
https://img-blog.csdn.net/20170926152940962?watermark/2/text/aHR 0 cDovL 2 Jsb 2 cuY 3 Nkbi 5 uZXQvenlsampm/font/5 L 6 L 2 T/fontsize/400/fill/I 0 JBQFCAMA==/diolve/70/gravity/Center[挿入]