2015-06-20 66 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();