使用 jquery 单击文本框时显示帮助程序文本

发布于 2024-07-30 06:16:50 字数 492 浏览 1 评论 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);
    });
});

I want to display helper text on clicking on the text boxes.
eg: If I click a text box it should help us by saying what to type: Enter username here

I have tried below given code but the text "Enter username" is fading out, I want the text to be displayed until the focus is changed to another text box.

please, suggest some code for this type.

<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);
    });
});

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

笔落惊风雨 2024-08-06 06:16:51

像下面这样的东西应该可以做到

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

这里是一个工作演示

Something like the following should do it

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

Here is a Working Demo

夜声 2024-08-06 06:16:51

我不知道为什么你要操纵 CSS 显示属性以及使用 fadeIn/fadeOut:

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

I'm not sure why you're manipulating the CSS display property as well as using fadeIn/fadeOut:

$(document).ready(function(){
    $("input").focus(function () {
         $(this).next("span").fadeIn(1000);
    }).blur(function() {
        $(this).next("span").fadeOut(1000);
    });
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文