jquery獲得焦點與失去焦點改變文本框背景圖的寫法

<script type="text/javascript">
        $(function () {
            //文本框樣式切換
            $(".username").focus(function () {
                $(this).removeClass("usernamefocus").addClass("username");
            }).blur(function () {
                $(this).removeClass("username").addClass("usernamefocus");
            });
            $(".password").focus(function () {
                $(this).removeClass("password").addClass("passwordfocus");
            }).blur(function () {
                $(this).removeClass("passwordfocus").addClass("password");
            });
            //按鈕樣式切換
            $(".button_one").hover(
            function () {
                $(this).removeClass("button_one").addClass("button_two");
            },
            function () {
                $(this).removeClass("button_two").addClass("button_one");
            }
            );
            $(".button_two").hover(
            function () {
                $(this).removeClass("button_one").addClass("button_two");
            },
            function () {
                $(this).removeClass("button_two").addClass("button_one");
            }
            );
        });
    </script>

發佈留言