jQuery-blur()遇到alert()

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <script src="jQuery/jquery-3.3.1.min.js" type="text/javascript" charset="utf-8"></script>
    </head>
    <body>
        <!--第一个文本框-->
        <input type="text"/>
        <!--第二个文本框-->
        <input type="text"/>
        
     
        <script type="text/javascript">
//            同时为多个input添加blur事件
            $("input").blur(function(){
//                弹出当前元素的下标值
                alert($(this).index())
            })
        </script>

 

    </body>
</html>

 问题原因:blur()事件里面有alert(),confirm(),等挂载进程的语句。会出现重复执行blur()事件

 解决办法:把blur()换成change()或其他事件

      把alert(),confirm(),等换成其他语句,如console.log(),或其他

posted @ 2019-06-18 15:50  梨子233  阅读(169)  评论(0)    收藏  举报