Created
June 19, 2013 11:10
-
-
Save wenjul/5813527 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
.placeholder{color:#A2A2A2;} | |
::-webkit-input-placeholder { /* WebKit browsers */ | |
color:#A2A2A2; | |
} | |
:-moz-placeholder { /* Mozilla Firefox 4 to 18 */ | |
color:#A2A2A2; | |
} | |
::-moz-placeholder { /* Mozilla Firefox 19+ */ | |
color:#A2A2A2; | |
} | |
:-ms-input-placeholder { /* Internet Explorer 10+ */ | |
color:#A2A2A2; | |
} |
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 supportsPlaceholder = 'placeholder' in document.createElement('input'); | |
$('[placeholder]').each(function () { | |
if (!supportsPlaceholder) { | |
var self = $(this); | |
self.val(self.attr('placeholder')).addClass('placeholder'); | |
self.focus(function(){ | |
if (self.val() == self.attr('placeholder')) { | |
self.val('').removeClass('placeholder'); | |
} | |
}); | |
self.blur(function(){ | |
if (self.val() == '') { | |
self.val(self.attr('placeholder')).addClass('placeholder'); | |
} | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment