2

我的代码

<!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>

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

4

3 回答 3

3

试试这个代码:)

<script type="text/javascript">

    $(function(){
        $("input").blur(function(){
            setTimeout(function(){  $("input").focus(); }, 20);
        });
        $("input").focusout(function(){
            setTimeout(function(){  $("input").focus(); }, 20);
        });
    });

</script>
于 2012-05-19T07:22:05.373 回答
0

尝试这样的事情

 <script>
    $(function(){
    $("input").blur(function(){

    setTimeout(function() {$(this).focus();}, 20);
          });
    });
 </script>
于 2012-05-19T06:46:34.217 回答
0

试试这个,它对我很有效:

<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>
于 2012-05-19T08:23:20.207 回答