jQuery live focus 函数问题

标签 jquery internet-explorer focus live

我有一些文本框想要隐藏然后在焦点上显示,但它似乎无法正常工作

这是我的 jQuery

$("#txt1").live('focus', function() {
    $(this).hide();
    $("#txt2").show().focus();
});

$("#txt2").live('blur', function() {
    if ($(this).attr("value") == "") {
        $(this).hide();
        $("#txt1").show();
    }
});

这是我的 HTML

<input type="text" id="txt1" value="Test" />

<input type="password" style="display:none" id="txt2" />

问题在于,在 Internet Explorer 中,实时焦点功能无法按预期工作。

它将焦点放在我的文本框上,但除非我再次单击它,否则我无法在该框中键入内容。

我有一个例子here on jsFiddle

第一个测试是有问题的。

我在第二个中添加了它,它按预期工作,但我需要它使用 live 函数工作。

有什么想法吗?

最佳答案

我这样做解决了问题

function pageLoad() {

$("#txt1").focus(function() {
    $(this).hide();
    $("#txt2").show().focus();
});

$("#txt2").blur(function() {
    if ($(this).attr("value") == "") {
        $(this).hide();
        $("#txt1").show();
    }
});

};

而不是将其放在document.ready()

关于jQuery live focus 函数问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5937853/

相关文章:

html - Internet Explorer 问题与 sukerfish 下拉菜单

c# - ASP.Net MVC : How to customize validation message showing

jquery - jQuery 中的 Ajaxform

javascript - IE和Firefox正则表达式问题

html - 如何删除 css 中焦点上闪烁的光标?

macos - 保持 NSWindow 最前面

jquery - 在文本框中的最后一个字符之后设置焦点

php - 如何在Jquery中隐藏/显示多个对象?

javascript - 如何操纵每次滚动运动的值?

internet-explorer - 如何从 Internet Explorer 11 降级到 Internet Explorer 10?