0

私はこのコードを持っています:

$(document).on({
    focus: function(){
        if ( $(this).val() == inputvalue ){
            $(this).val("");
        }
        $(this).css({"box-shadow":"inset 2px 2px 5px #c7bda8"});
    },
    blur: function(){
        if ( $(this).val() == "" ){
            $(this).val(inputvalue);
        }
        $(this).css({"box-shadow":"none"});
    }
}, "input[type='text']");

フォーカスされる入力フィールドの値を含む変数( "inputvalue")を渡すにはどうすればよいですか?

前もって感謝します :)

4

1 に答える 1

1

次のように、より高いスコープで定義してみてください。

var inputvalue = $('input').val();

$(document).on({
    focus: function(){
        if ( $(this).val() == inputvalue ){
            $(this).val("");
        }
        $(this).css({"box-shadow":"inset 2px 2px 5px #c7bda8"});
    },
    blur: function(){
        if ( $(this).val() == "" ){
            $(this).val(inputvalue);
        }
        $(this).css({"box-shadow":"none"});
    }
}, "input[type='text']");
于 2012-08-17T11:36:08.627 に答える