「プレースホルダー」属性を使用しています。入力フィールドのプレースホルダー テキスト用
IE 化身でもこの機能が必要です。
プレースホルダーを FOCUS で非表示にしたい! 私が見つけたすべての回避策は、最初のタイプが入力されたときにプレースホルダーを非表示にします。
私はそれを自分で解決することはできません。フォーカス時に入力のプレースホルダー テキストを削除するだけでなく、入力値が空の場合はぼかし時にそのプレースホルダー テキストを回復する必要があります。
これを機能させようとしています
jQuery(document).ready(function () {
jQuery('[placeholder]').focus(function() {
input = jQuery(this);
if (input.val() == input.attr('placeholder')) {
input.val('');
input.removeClass('placeholder');
input.attr('placeholder','')
}
}).blur(function() {
var input = jQuery(this);
if (input.val() == '' || input.val() == input.attr('placeholder')) {
input.addClass('placeholder');
input.val(input.attr('placeholder'));
}
}).blur().parents('form').submit(function() {
jQuery(this).find('[placeholder]').each(function() {
var input = jQuery(this);
if (input.val() == input.attr('placeholder')) {
input.val('');
}
})
});
});
これにより、プレースホルダーの値が「(何もない)」に変更され、動作は希望どおりですが、ブラーでは「(何もない)」ため、プレースホルダーの値を回復できません
//アップデート
私のための解決策:
$(function()
{
$('input').each(function()
{
$(this).val($(this).attr('holder'));
});
$('input').focus(function()
{
if($(this).attr('holder')==$(this).val())
{
$(this).val('');
}
});
$('input').focusout(function()
{
if($.trim($(this).val())=='')
{
var holder = $(this).attr('holder');
$(this).val(holder);
}
});
});