Menu

STEP 5 - 変数this と each()メソッドで改善!

STEP 4 での問題点が解消されました。

jQuery Code

$(function() {
	$(".textbox").each(function(){
		var labelText;
		labelText = $(this).val();
		$(this).focus(function(){
			if( $(this).val() == labelText ){
				$(this).val("");
			}
		}).blur(function(){
			if( $(this).val() == "" ){
				$(this).val(labelText);
			}
		});
	});
});

jQuery.com 公式ドキュメント

Chapter 9