Created
August 10, 2011 02:27
-
-
Save aisuii/1135934 to your computer and use it in GitHub Desktop.
placeholder もどき
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function($) { | |
var dataKey = "phText"; | |
var placeholderColor = "#aaa"; | |
$("[placeholder]").each(function() { | |
var $elem = $(this); | |
var originalText = $elem.attr("placeholder"); | |
var originalColor = $elem.css("color"); | |
$.data(this, dataKey, originalText); | |
if(this.value == "") { | |
this.value = originalText; | |
$elem.css({color: placeholderColor}); | |
} | |
$elem.focus(function() { | |
$elem.css({color: originalColor}); | |
if(this.value == originalText) { | |
this.value = ""; | |
} | |
}).blur(function() { | |
if(this.value == "") { | |
this.value = originalText; | |
$elem.css({color: placeholderColor}); | |
} else { | |
$elem.css({color: originalColor}); | |
} | |
}); | |
}) | |
$("form").submit(function() { | |
$("[placeholder]", this).each(function() { | |
if(this.value == $.data(this, dataKey)) { | |
this.value = ""; | |
} | |
}); | |
}); | |
})(jQuery) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment