input内のテキスト表示しfocusするjQueryプラグイン
- Category :
- Javascript
…ここからが続き
ダウンロード・使い方
ダウンロード元「jQuery Inline Form Labels」
head内
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('input[title]').each(function() {
if($(this).val() === '') {
$(this).val($(this).attr('title'));
}
$(this).focus(function() {
if($(this).val() == $(this).attr('title')) {
$(this).val('').addClass('focused');
}
});
$(this).blur(function() {
if($(this).val() === '') {
$(this).val($(this).attr('title')).removeClass('focused');
}
});
});
});
</script>
XHTML
<p><input type="text" title="Email Address" value="" /></p> <p><input type="text" name="" id="" title="First Name" value="" /></p> <p><input type="text" name="" id="" value="" /></p>
title に表示したいテキストを記述して下さい。
CSS
input {
border: 1px solid #CCC;
color: #999;
font: inherit;
padding: 4px;
width: 230px;
}
focus 前のボーダーの色やテキストの色を指定。
input:focus, input.focused
{ border-color: #333; color: #333; }
focus 後のボーダーの色やテキストの色を指定。






Comments
tokoさん
自分はまだ検索ボックスでしか使った事がなかったので、そのようになると知りませんでした;;
それといろいろ試してはみたのですが自分では対処法は分かりませんでした…
お力になれなくてすみません。
これ便利ですね^^試しに入れてみたところうまくできたのですがフォームでPOSTすると何も入力しない場合titleで指定した値が送られてしまいます^^;
これってなんとかならないものでしょうか?