表单获取焦点失去焦点

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>表单非空校验</title>
    <script type="text/javascript" src="jquery.min.js"></script>
    <style>
    .wait{color: green}
    </style>
</head>
<body>
<input type="text" class="ipt">
    <script type="text/javascript">
        $(function(){
            $(".ipt").blur(function(){
                if($(this).val()==""){
                $(".ipt").val("请输入关键词").addClass("wait");
                }
            });
            $(".ipt").focus(function(){
            if($(".ipt").val()=="请输入关键词"){
            $(".ipt").val("").removeClass("wait");
            }
            });
        })
    </script>
</body>
</html>

 

posted @ 2015-09-11 11:30  名字不能缺  阅读(2053)  评论(0编辑  收藏  举报