Created
August 10, 2011 03:18
-
-
Save aisuii/1136024 to your computer and use it in GitHub Desktop.
android の場合 placeholder 属性けずって placeholder もどきの挙動をするようにする
This file contains 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
if(navigator.userAgent.match(/android/i)) { | |
(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); | |
$elem.removeAttr("placeholder"); | |
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