0

伙计们 :)

$('#loginbox').blur(function(){
    var focusedInputs = null;
    $('#loginbox table tbody tr td input').focus(function(){
        focusedInputs = this;
    });
    alert(focusedInputs);
    if (focusedInputs == null) {
        $('#loginbox').stop().fadeOut('fast',function(){
            $('#loginlink').prop('href','#login');
            window.location.hash = '#';
        });
        $('#loginlink').removeClass('selected');
        $('.tooltip').css('display','none');
        Cufon.refresh();
    }
});

它提醒我'nul',但如果我在焦点函数中写alert(focusedInputs):

    $('#loginbox table tbody tr td input').focus(function(){
        focusedInputs = this;
        alert(focusedInputs);
    });

它提醒一个元素...我不知道问题出在哪里...谢谢!

4

1 回答 1

0

试试这个,除非您打算取消绑定,否则您真的不应该在模糊事件中绑定焦点事件。

var focusedInputs = null;
$('#loginbox table tbody tr td input').focus(function(){
    focusedInputs = this;
}); // do you also need a blur event here to clear focusedInputs?


$('#loginbox').blur(function(){
    alert(focusedInputs);    
    if (focusedInputs == null) {
        $('#loginbox').stop().fadeOut('fast',function(){
            $('#loginlink').prop('href','#login');
            window.location.hash = '#';
        });
        $('#loginlink').removeClass('selected');
        $('.tooltip').css('display','none');
        Cufon.refresh();
    }
});
于 2012-07-10T21:31:18.277 回答