我有一些文本框想要隐藏然后在焦点上显示,但它似乎无法正常工作
这是我的 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/