Javascript .show()之后的jQuery.focus()

Javascript .show()之后的jQuery.focus(),javascript,jquery,focus,show,synchronous,Javascript,Jquery,Focus,Show,Synchronous,下面的代码隐藏了一个文本框并显示了另一个文本框。当下一个出现时,我需要光标在上面,所以我对它调用.focus()。然而,即使我将调用.focus()作为第二个参数,它仍然没有聚焦。有什么想法吗 $(document).ready(function(){ $('.dummy-password-input').on('click', function() { $(this).hide(); $(this).next().show(0, function() {

下面的代码隐藏了一个文本框并显示了另一个文本框。当下一个出现时,我需要光标在上面,所以我对它调用
.focus()
。然而,即使我将调用
.focus()
作为第二个参数,它仍然没有聚焦。有什么想法吗

$(document).ready(function(){
    $('.dummy-password-input').on('click', function() {
        $(this).hide();
        $(this).next().show(0, function() {
            $(this).focus();
        });
    });
});

出现这种行为,因为$(this)指的是刚刚隐藏的输入字段,如更改代码:

        $(this).next().show(0, function() {
            $(this).next().focus();
        });
编辑:


检查一下

各位,很抱歉给你们添麻烦。结果是,在对它进行了更多的处理之后,我的DOM遍历并不完全正确。我去掉了输入框周围的div,效果很好。谢谢。

如果你能给我们一把小提琴来编辑,可能会更好。
$(document).ready(function(){
    $('.dummy-password-input').on('click', function() {
        $(this).hide();
        $(this).next().show().focus();
    });
});