Created
January 26, 2016 07:13
-
-
Save leohxj/93fda7baf9cb3839abc7 to your computer and use it in GitHub Desktop.
supportPlaceholder.js
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
| 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