是否有用于淡出文本框提示的 jQuery 插件?

发布于 2024-10-27 01:56:21 字数 490 浏览 6 评论 0原文

我想知道是否有一个可用的 jQuery 插件可以在文本框为空时显示提示。

我发现的是: http://remysharp.com/2007 /01/25/jquery-tutorial-text-box-hints/。但是,这仅充当 placeholder HTML5 属性。我正在寻找的是一个显示多个淡入淡出提示的插件,如 http://www.wolframalpha.com /。 (编辑:我的意思是文本框中的灰色文本 - 不是工具提示。)

虽然自己创建它可能不会太麻烦,但我不赞成重新发明轮子的理论 -那么有人知道这样的插件是否已经可用吗?

谢谢。

I was wondering whether there is a jQuery plugin available which can show hints in a textbox when it is empty.

What I found was: http://remysharp.com/2007/01/25/jquery-tutorial-text-box-hints/. However, this just acts as the placeholder HTML5 attribute. What I'm looking for is rather a plugin that shows multiple hints with fading, as on http://www.wolframalpha.com/. (Edit: I mean the grey text in the textbox - not the tooltip.)

Although it might not be too much trouble to create it myself, I don't subscribe to the theory of reinventing the wheel - so does anyone know if such a plugin is already available?

Thanks.

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

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

发布评论

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

评论(4

眼泪也成诗 2024-11-03 01:56:21

我自己做了一个,这样它完全符合我的需求: http://jsfiddle.net/42t6R/2/

它很简单,但效果很好。

编辑:新版本的错误较少,为什么不将其作为插件提交:)

http://plugins.jquery.com/project/fadehints

http://jsfiddle.net/ 9rgHg/2/

(function( $, undefined ) {

    $.fn.fadehints = function( data, speed ) {
        var i = 0;
        var $this = $( this );
        var offset = $this.offset();
        var $input = $("<input>").css( "position",          "absolute"                 )
                                 .css( "left",              offset.left                )
                                 .css( "top",               offset.top                 )
                                 .css( "background-color",  "transparent"              )
                                 .css( "color",             "gray"                     )
                                 .css( "border",            0                          )
                                 .css( "padding",           2                          )
                                 .css( "font-size",         $this.css( "font-size"   ) )
                                 .css( "font-family",       $this.css( "font-family" ) );

        var $parent = $this.parent();
        var $div = $( "<div>" ).append( $this.detach(), $input );

        var change = function() {
            if( i >= data.length ) {
                i = 0;
            }
            $input.hide().val( data[i] ).fadeIn( 1000 );
            i++;
        };

        $this.bind( "focus keydown", function(e) {
            if( !( e.bubbles == null ) ) { // Only clear if event was triggered by user
                window.clearInterval( interval );
                $input.hide();
            }
        } );

        $input.bind( "click focus", function() {
            window.clearInterval( interval );
            $this.focus(); // $this === the real textbox
            $( this ).hide(); // $(this) === the overlap textbox
        } );

        $this.click( function() {
            $input.hide();
            window.clearInterval( interval );
        } );

        $this.blur( function() {
            window.clearInterval( interval );
            if( $this.val() === "" && $this[0] !== document.activeElement ) {
                if( !$input.is(":visible")) {
                change();
                }
                interval = window.setInterval( change, speed );
            }
        } );
        $parent.append( $div );

        change(true);
        var interval = window.setInterval( change, speed );


        return $this;
    };

})(jQuery);

$(function() {
    $('#tb').fadehints([
        "test1", "test2"
    ]);
});

I made one up myself, so that it fits my needs completely: http://jsfiddle.net/42t6R/2/.

It's simple but it works just nicely.

Edit: New version which has less bugs, also why not submit it as a plugin :)

http://plugins.jquery.com/project/fadehints

http://jsfiddle.net/9rgHg/2/

(function( $, undefined ) {

    $.fn.fadehints = function( data, speed ) {
        var i = 0;
        var $this = $( this );
        var offset = $this.offset();
        var $input = $("<input>").css( "position",          "absolute"                 )
                                 .css( "left",              offset.left                )
                                 .css( "top",               offset.top                 )
                                 .css( "background-color",  "transparent"              )
                                 .css( "color",             "gray"                     )
                                 .css( "border",            0                          )
                                 .css( "padding",           2                          )
                                 .css( "font-size",         $this.css( "font-size"   ) )
                                 .css( "font-family",       $this.css( "font-family" ) );

        var $parent = $this.parent();
        var $div = $( "<div>" ).append( $this.detach(), $input );

        var change = function() {
            if( i >= data.length ) {
                i = 0;
            }
            $input.hide().val( data[i] ).fadeIn( 1000 );
            i++;
        };

        $this.bind( "focus keydown", function(e) {
            if( !( e.bubbles == null ) ) { // Only clear if event was triggered by user
                window.clearInterval( interval );
                $input.hide();
            }
        } );

        $input.bind( "click focus", function() {
            window.clearInterval( interval );
            $this.focus(); // $this === the real textbox
            $( this ).hide(); // $(this) === the overlap textbox
        } );

        $this.click( function() {
            $input.hide();
            window.clearInterval( interval );
        } );

        $this.blur( function() {
            window.clearInterval( interval );
            if( $this.val() === "" && $this[0] !== document.activeElement ) {
                if( !$input.is(":visible")) {
                change();
                }
                interval = window.setInterval( change, speed );
            }
        } );
        $parent.append( $div );

        change(true);
        var interval = window.setInterval( change, speed );


        return $this;
    };

})(jQuery);

$(function() {
    $('#tb').fadehints([
        "test1", "test2"
    ]);
});
物价感观 2024-11-03 01:56:21

嘿,primvdb,这个怎么样?

Hey there primvdb, what about this?

不乱于心 2024-11-03 01:56:21

试试这个:http://jqueryfordesigners.com/coda-popup-bubbles/
这应该就是您要找的。

Try this : http://jqueryfordesigners.com/coda-popup-bubbles/
It should be what you're looking for.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文