HTML5 placeholder在input元素上引入了属性,允许显示灰色的默认文本.
可悲的是,包括IE 9在内的Internet Explorer不支持它.
那里已经有一些占位符模拟器脚本了.它们通常通过将默认文本放入输入字段,将其设置为灰色并在您聚焦输入字段后再次将其删除来工作.
这种方法的缺点是占位符文本在输入字段中.从而:
我想有一个解决方案,其中占位符文本不在输入本身.
我知道有很多占位符问题,但我想完善我的.
我当前的代码工作得很好并且做了它应该做的事情.问题是,当我去放置"密码"占位符时,它会将占位符放在屏蔽字符中.关于如何解决这个问题的任何想法?
$(function() {
if(!$.support.placeholder) {
var active = document.activeElement;
$(':text').focus(function () {
if ($(this).attr('placeholder') != '' && $(this).val() == $(this).attr('placeholder')) {
$(this).val('').removeClass('hasPlaceholder');
}
}).blur(function () {
if ($(this).attr('placeholder') != '' && ($(this).val() == '' || $(this).val() == $(this).attr('placeholder'))) {
$(this).val($(this).attr('placeholder')).addClass('hasPlaceholder');
}
});
$(':text').blur();
$(active).focus();
$('form').submit(function () {
$(this).find('.hasPlaceholder').each(function() { $(this).val(''); });
});
var active = document.activeElement;
$(':password').focus(function () {
if ($(this).attr('placeholder') != '' && $(this).val() == $(this).attr('placeholder')) {
$(this).val('').removeClass('hasPlaceholder');
}
}).blur(function () {
if ($(this).attr('placeholder') != '' && ($(this).val() …Run Code Online (Sandbox Code Playgroud)