2012-03-03 1 views
0

このテキストフィールドにmysqlエコーがある場合、どのようにjqueryヒントを上書きするのですか? 現在、私はjqueryのヒントを持っていますが、フィールドにmysqlの値があり、それをエコーし​​たときにjqueryのヒントが表示されています。mysqlでjqueryヒントをオーバーライドする方法echo

PHP jqueryのヒントスクリプト

$(document).ready(function() { 
    //Shows the title in the text box, and removes it when modifying it 
    $('input[title]').each(function (i) { 
     $(this).val($(this).attr('title')).addClass('hint'); 

     $(this).focus(function() { 
      if ($(this).val() == $(this).attr('title')) { 
       $(this).val('').removeClass('hint'); 
      } 
     }); 

     $(this).blur(function() { 
      if ($(this).val() == '') { 
       $(this).val($(this).attr('title')).addClass('hint'); 
      } 
     }); 
    }); 

    //Clear input hints on form submit 
    $('form').submit(function() { 
     $('input.hint').val(''); 
     return true; 
    }); 
}); 

フォームのテキストフィールド

<input type="text" name="name" id="name" title="insert here" value=<?php echo $row3['name']?> /> 
+1

**コードをインデントする必要があります。それ以外に、 'placeholder'属性を使わない理由はありますか?現代のすべてのブラウザでサポートされています。古いブラウザでは、動作させるためにhttps://github.com/mathiasbynens/jquery-placeholderがあります。 – ThiefMaster

答えて

1

次のコードで$(this).val($(this).attr('title')).addClass('hint');を置き換えます。しかし、あなたが本当にplaceholder属性を使用することを検討すべきである

if(!$(this).val()) { 
    $(this).val($(this).attr('title')).addClass('hint'); 
} 

。古いブラウザでも動作させるには、単にスクリプトを追加するだけです。https://github.com/mathiasbynens/jquery-placeholder

+0

ありがとうございました。これはどのブラウザバージョン(IE)で動作しませんか?また、私は 'テキストの挿入'の色を変更するのですが、テキストフィールドの色は変更しませんか? – Lukus

関連する問題