Created
December 18, 2012 13:15
-
-
Save jswebschmiede/4327894 to your computer and use it in GitHub Desktop.
Cross-Browser Placeholder Support, auch für Passwort Felder im IE, mit Modernizr.
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
/* Modernizr load */ | |
Modernizr.load({ | |
test : Modernizr.input.placeholder, | |
nope : './js/ext/placeholderfix.js' | |
}); |
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
/* placeholderfix script */ | |
$(function() { | |
var input = document.createElement("input"); | |
if (('placeholder' in input) == false) { | |
$('[placeholder]').focus(function() { | |
var i = $(this); | |
if (i.val() == i.attr('placeholder')) { | |
i.val('').removeClass('placeholder'); | |
if (i.hasClass('password')) { | |
i.removeClass('password'); | |
this.type = 'password'; | |
} | |
} | |
}).blur(function() { | |
var i = $(this); | |
if (i.val() == '' || i.val() == i.attr('placeholder')) { | |
if (this.type == 'password') { | |
i.addClass('password'); | |
this.type = 'text'; | |
} | |
i.addClass('placeholder').val(i.attr('placeholder')); | |
} | |
}).blur().parents('form').submit(function() { | |
$(this).find('[placeholder]').each(function() { | |
var i = $(this); | |
if (i.val() == i.attr('placeholder')) | |
i.val(''); | |
}) | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment