0

我想在单击文本框时显示帮助文本。例如:如果我单击一个文本框,它应该可以帮助我们说出要输入的内容:在此处输入用户名

我尝试了下面给定的代码,但文本“输入用户名”正在淡出,我希望显示文本,直到焦点更改为另一个文本框。

请为这种类型建议一些代码。

<input type = "text"/><span>Enter username</span>
<input type = "text"/><span>Enter password</span>     


$(document).ready(function(){
    $("input").focus(function () {
         $(this).next("span").css('display','inline').fadeOut(1000);
    });
});
4

2 回答 2

4

像下面这样的事情应该这样做

$(function(){
    $("input")
        .focus(function () {
            $(this).next("span").fadeIn(1000);
        })
        .blur(function () {
             $(this).next("span").fadeOut(1000);
        }); 
});

这是一个 工作演示

于 2009-07-30T11:50:05.703 回答
1

我不确定您为什么要操纵 CSS 显示属性以及使用淡入/淡出:

$(document).ready(function(){
    $("input").focus(function () {
         $(this).next("span").fadeIn(1000);
    }).blur(function() {
        $(this).next("span").fadeOut(1000);
    });
});
于 2009-07-30T11:52:56.740 回答