2015-05-30 95 views
0

在我的網站中,登錄窗口使用AJAX調用以POPUP的形式打開。 請參考下面的屏幕抓取:將焦點設置在AJAX POPUP中的文本框中加載

$('#hrefLogin').click(function() { 
    var url = $('#divLogin').data('request-path'); 

    $.ajax({ 
     url: url, 
     type: 'GET', 
     success: function (data) { 
      ////Render the partial view HTML returned by the action method 
      $("#divLogin").html(data); 

      $.fancybox({ 
       href: "#divLogin", 
       'maxWidth': 420, // set the width 
       'minHeight': 400, 
       'maxHeight': 400, 
       'height':'auto', 
       'autoSize': false     
      }); 

      $.fancybox.update(); 

      ////Reparse html data to enable MVC data annotation work. 
      $('form').removeData('validator'); 
      $('form').removeData('unobtrusiveValidation'); 
      $.validator.unobtrusive.parse('form'); 
     } 
    }); 
}); 

登錄窗口有兩個輸入域用戶名和密碼。 當彈出打開時,我需要在UserName字段上設置焦點。

非常感謝,

問候, 拉莉莎

+0

爲什麼不只是使用$(「。username」)。焦點() –

+0

謝謝,但我需要實現這個?在登錄頁面內或彈出窗口的位置 – user3657053

回答

0

我要完成我的評論在這裏,我完整的答案。

我看到你使用fancybox,so I looked at it,並看到有一個選項可以在彈出窗口完成後執行某些操作。

所以找你要在找你的代碼是這樣的:

$("#divLogin").html(data); 

$.fancybox({ 
    href: "#divLogin", 
    'maxWidth': 420, // set the width 
    'minHeight': 400, 
    'maxHeight': 400, 
    'height':'auto', 
    'autoSize': false, 
    onComplete : function(){ 
     $(".username").focus(); 
    };     
}); 

$.fancybox.update(); 

所以,重點是已成功彈出的內容顯示後更新。

祝你好運,玩得開心。

相關問題