Skip to content

Instantly share code, notes, and snippets.

@leohxj
Created January 26, 2016 07:13
Show Gist options
  • Select an option

  • Save leohxj/93fda7baf9cb3839abc7 to your computer and use it in GitHub Desktop.

Select an option

Save leohxj/93fda7baf9cb3839abc7 to your computer and use it in GitHub Desktop.
supportPlaceholder.js
var supportPlaceHolder = function() {
// first, detect the placeholder attribute
var isPlaceholder = function(){
var input = document.createElement('input');
return 'placeholder' in input;
}
if(!isPlaceholder()){
$('[placeholder]').each(function(){
var defaultValue = $(this).attr("placeholder");
if($.trim($(this).val())==""){
$(this).val(defaultValue).css("color","#999");
}
$(this).focus(function(){
var defaultValue = $(this).attr("placeholder");
if($.trim($(this).val())==defaultValue){
$(this).val("").css("color","#333");
}
}).blur(function(){
var defaultValue = $(this).attr("placeholder");
if($.trim($(this).val())==""){
$(this).val(defaultValue).css("color","#999")
}
});
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment