0

以下の js スクリプトを使用しており ( http://blog.enriquez.me/2009/3/28/jquery-plugin-ezpz-hint/hint.css('color','#999999');から) 、入力フィールド内のラベル テキストを灰色にする部分を追加しました。焦点が合っていません。しかし、私が理解できないのは、入力フィールドで一度フォーカスされたテキストを黒 (#000) にする方法です。以下のコードのどこに行けばよいか、誰か説明できますか? (または、何らかの形でスタイルを css に追加する必要がある場合は?)

(function($){
$.fn.ezpz_hint = function(options){
    var defaults = {
        hintClass: 'ezpz-hint',
        hintName: 'ezpz_hint_dummy_input'
    };
    var settings = $.extend(defaults, options);

    return this.each(function(i){
        var id = settings.hintName + '_' + i;
        var hint;
        var dummy_input;
        if ($(this).hasClass('select2-focusser') || $(this).hasClass('select2-input'))
            {
                    return true; //skips to the next iteration for select2 inputs
                }

        // grab the input's placeholder attribute
        text = $(this).attr('placeholder');

        // create a dummy input and place it before the input
        $('<input type="text" id="' + id + '" value="" />')
            .insertBefore($(this));

        // set the dummy input's attributes
        hint = $(this).prev('input:first');
        hint.attr('class', $(this).attr('class'));
        hint.attr('size', $(this).attr('size'));
        hint.attr('autocomplete', 'off');
        hint.attr('tabIndex', $(this).attr('tabIndex'));
        hint.addClass(settings.hintClass);
        hint.val(text);
        hint.css('color','#999999');

        // hide the input
        $(this).hide();

        // don't allow autocomplete (sorry, no remember password)
        $(this).attr('autocomplete', 'off');

        // bind focus event on the dummy input to swap with the real input
        hint.focus(function(){
            dummy_input = $(this);
            $(this).next('input:first').show();
            $(this).next('input:first').focus();
            $(this).next('input:first').unbind('blur').blur(function(){
                if ($(this).val() == '') {
                    $(this).hide();
                    dummy_input.show();
                }
            });
            $(this).hide();
        });
        // swap if there is a default value
        if ($(this).val() != ''){
            hint.focus();
            hint.css('color','#000000');
        };
    });
};
})(jQuery);

ありがとう!

4

1 に答える 1