2015-06-20 65 views
1

这是我的看法。隐藏从Jquery UI中闪烁的光标模态dailog

<div class="login-card"> 
    <h1>Log-in</h1> 
    <br> 

    <input type="text" id="txtUser" placeholder="Username" autofocus value="adm"> 
    <input type="password" id="txtPass" placeholder="Password" value="adm"> 
    <input type="button" name="btnLogin" class="login login-submit" value="Login" onclick="btnLoginClick($('#txtUser').val(), $('#txtPass').val())"> 
</div> 

@globalHelper.CreateDivForModalDialog("divLoginError", "Error", "Login Failed ! Try again") 

这是我的脚本。

$(document).ready(function() { 
    $('#divLoginError').hide(); 
}) 

function btnLoginClick(username, password) { 
    $.ajax({ 
     url: "/Home/ValidateLogin", 
     data: { username: username, password: password }, 
     dataType: "json", 
     success: function (data) { 
      var dialogError = $("#divLoginError").dialog({ 
       modal: true, 
       autoOpen: false, 
       position: { my: "center", at: "center center", of: window }, 
       height: dialogSize.getHeight(25), 
       width: dialogSize.getWidth(25), 
       overflow: scroll 
      }); 

      if (data.toString() == 'true') { 
       window.location.href = "/Home/FWMenu"; 
      } 
      else { 
       dialogError.dialog("open"); 
       $('#txtUser').focus(); 
      } 
     }, 
     error: function (e) { 
      alert('error'); 
     } 
    }); 
} 

问题是上登录失败时的错误消息dailog盒即将到来,其与闪烁光标,该闪烁在后面的用户名的textarea的dailog框光标表示。为什么会发生以及如何解决它? 下面是两个屏幕截图。

enter image description here

现在看这是它实际上是闪烁的光标。

enter image description here

+0

,当你按下'F7'它不会停止? –

+0

而不是在对话框打开后立即设置焦点'$('#txtUser')。focus();'。您可以将输入文本焦点设置为“对话关闭事件”。 JQuery模型对话框关闭可以在JQuery事件中捕获 - http://stackoverflow.com/questions/171928/hook-into-dialog-close-event – ramiramilu

+0

对于我上面的答案,这里是小提琴 - http://jsfiddle.net/db5SX/5216 /。让我知道它是否有帮助。 – ramiramilu

回答

0

这是由于IE而不是JQuery的。事实上,我在IE8中遇到了同样的问题。当我在页面上显示加载图像时,光标在我的搜索框中保持空白。
在我测试过的Firefox和Chrome中,一切正常。

+0

是的,你是对的。我找到了另一种方式。感谢您的回复。 – Amit

0

我需要使用下面的代码片段。

$(this).parent().find("txtUser.hidden").focus(); 

而不是

$('#txtUser').focus();