当我使用on blur将焦点返回到文本框时,JQuery>插入符号/光标不会闪烁

当我使用on blur将焦点返回到文本框时,JQuery>插入符号/光标不会闪烁,jquery,textbox,cursor,focus,onblur,Jquery,Textbox,Cursor,Focus,Onblur,我有一个只能接受数字的文本框。我使用JQuery onblur方法验证输入到文本框中的内容。如果验证失败,我会弹出一个警报,告诉用户有问题,然后通过编程将焦点返回文本框 我的问题是,当我将焦点返回到文本框时,光标/插入符号不会闪烁。它就在那里,我可以在文本框中键入,而不必先单击它来选择它。但是,在我实际单击文本框之前,光标不会闪烁。我注意到,如果我不使用警报弹出窗口,光标会闪烁 我设置了一个小的html页面来说明。。这是代码 <html> <head> <scrip

我有一个只能接受数字的文本框。我使用JQuery onblur方法验证输入到文本框中的内容。如果验证失败,我会弹出一个警报,告诉用户有问题,然后通过编程将焦点返回文本框

我的问题是,当我将焦点返回到文本框时,光标/插入符号不会闪烁。它就在那里,我可以在文本框中键入,而不必先单击它来选择它。但是,在我实际单击文本框之前,光标不会闪烁。我注意到,如果我不使用警报弹出窗口,光标会闪烁

我设置了一个小的html页面来说明。。这是代码

<html>
<head>
<script type="text/javascript" src="Plugins/jquery.js"></script>

<SCRIPT type="text/javascript">
$(document).ready(function() {

    $(document).on("blur","#qty_text", function() {
        var myregexp = /^[0]$|^[1-9][0-9]*$/;
            if( myregexp.test( $("#qty_text").val()) ){
                alert("Input Valid");
            }else{
                setTimeout(function(){
                    alert("Not a valid number");
                    $( "#qty_text" ).focus();
                }, 10);   
            }
    });

});
</script>
</head>

<body>
    <input type="text" id="qty_text">
</body>
</html>

有没有办法在用户确认退出警报弹出窗口后,在文本框中仍然显示闪烁的光标?谢谢。

如果有人在意,我最终使用了一个名为SimpleModel的jQuery模态对话框插件。请看这里:

当您离开文本框单击,验证测试失败时,对话框打开,几秒钟后关闭,留下插入符号光标,无论您称之为什么,它都会在文本框中明显闪烁。成功

一个小代码片段:

<SCRIPT type="text/javascript">
$(document).ready(function() {
    $(document).on("blur","#qty_text", function() {
       var myregexp = /^[0]$|^[1-9][0-9]*$/;
        if( myregexp.test( $("#qty_text").val()) ){
            alert("Input Valid");
        }else{
            $('#simple-modal').modal({
                onOpen: function (dialog) {
                // If you use the onOpen callback, you must "show"
                // the overlay, data and container elements manually                    
                    dialog.overlay.fadeIn('slow');
                    dialog.container.fadeIn('slow');
                    dialog.data.fadeIn('slow');
                },
                onShow: function (dialog) {
                // Close the dialog automatically three seconds after it opens
                    setTimeout(function(){
                        dialog.data.hide();
                        dialog.container.hide();
                        dialog.overlay.fadeOut('slow', function () {
                            $.modal.close(); // must call this!
                            $( "#qty_text" ).focus();
                        });
                    }, 3000);
                }
          });
        }
    }); //<-- end of $(document).on("blur",..)
}); //<-- end of $(document).ready()
</script>
下面是带有DIV的主体,DIV用于设置对话框的格式:

<body>
<input type="text" id="qty_text">

<!-- The SimpleModal Dialog -->
    <div class="simple-modal" id="simple-modal">
       <div class="simple-modal-header">
         <h1>Quantity Error</h1>
       </div>
       <div class="simple-modal-body">
         <div class="contents">
           <p>Quantity Entered is not a Number</p>
           <p>Please Try Again</p>
         </div>
       </div>
      <div class="simple-modal-footer"></div>
    </div>
</body>
我不知道为什么在单击Javascript警报弹出窗口上的“确定”按钮后,返回焦点后文本框中不会出现闪烁的插入符号。如果有人能给我解释一下,我还是会很感激的