jquery中获取焦点和失去焦点事件

<script src="../js/jquery-1.12.4.min.js"></script>
    <script>
        $(function(){
            // 获取焦点事件,不传参 focus
            $('.one').focus();

            // 监听焦点事件,能返回
            $('.one').focus(function(){
                console.log("获取到焦点!")
            })
            // 失去焦点事件 blur 能返回
            $('.one').blur(function(){
                console.log("失去焦点了?")
            })

            // focus()焦点获取.可以返回
            // blur()捕捉失去焦点,并返回
        })
    </script>

下面代码放在html body中

<!-- 焦点事件,即进入界面鼠标定位点,用户可以直接输入 -->
    <input type="text" class="one"><br>
    <input type="text" class="two">

猜你喜欢

转载自blog.51cto.com/10412806/2114354