将输入集中在模糊事件不起作用上

Focus input on blur event not working

本文关键字:事件 不起作用 模糊 输入 集中      更新时间:2023-09-26

我的代码

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script src="js/jquery.js"></script>
<script>
$(function(){
$("input").blur(function(){$(this).focus();});});</script>
</head>
<body>
<input type="text" >
</body>
</html>

它不会将输入集中在模糊事件上。为什么?建议解决方案?

试试这段代码:)

<script type="text/javascript">
    $(function(){
        $("input").blur(function(){
            setTimeout(function(){  $("input").focus(); }, 20);
        });
        $("input").focusout(function(){
            setTimeout(function(){  $("input").focus(); }, 20);
        });
    });
</script>

试试这个,它对我完美地工作:

<script>
$(function(){
    $("input").blur(function(){
        (function(that) {
            setTimeout(function(){
                var oldTabIndex = that.attr('tabindex');
                that.attr("tabindex", 1);
                $(window).focus();
                if (!that.is(':focus')) {
                    that.focus();
                }
                that.attr('tabindex', oldTabIndex);
            }, 50);
        })($(this));
    });
});
</script>

尝试这样的事情

 <script>
    $(function(){
    $("input").blur(function(){
    setTimeout(function() {$(this).focus();}, 20);
          });
    });
 </script>