5

テキストボックスが空のときにヒントを表示できるjQueryプラグインがあるかどうか疑問に思っていました。

私が見つけたのはhttp://remysharp.com/2007/01/25/jquery-tutorial-text-box-hints/です。ただし、これはplaceholderHTML5 属性として機能するだけです。私が探しているのは、http://www.wolframalpha.com/のように、フェードで複数のヒントを表示するプラグインです。(編集:ツールチップではなく、テキストボックス内の灰色のテキストを意味します。)

自分で作成するのはそれほど面倒ではないかもしれませんが、車輪を再発明するという理論には同意しません。そのようなプラグインが既に利用可能かどうか誰か知っていますか?

ありがとう。

4

4 に答える 4

1

自分のニーズに完全に合うように、自分で作成しました: 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"
    ]);
});
于 2011-03-25T22:07:05.100 に答える
0

これは役立つかもしれません:http ://www.webdesignbooth.com/15-jquery-plugins-to-create-an-user-friendly-tooltip/

于 2011-03-25T16:26:04.447 に答える
0

こんにちは、primvdb、これはどうですか?

于 2011-03-25T16:30:08.747 に答える
0

これを試してください: http://jqueryfordesigners.com/coda-popup-bubbles/ それはあなたが探しているものでなければなりません。

于 2011-03-25T16:30:09.537 に答える