我已经实现了以下脚本在IE中为输入框显示占位符,但它不适用于密码字段,请通知我。
<script>
jQuery(function() {
jQuery.support.placeholder = false;
test = document.createElement('input');
if('placeholder' in test) jQuery.support.placeholder = true;
});
// Placeholder for IE
$(function () {
if(!$.support.placeholder) {
var active = document.activeElement;
$(':text, textarea').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, textarea').blur();
$(active).focus();
$('form').submit(function () {
$(this).find('.hasPlaceholder').each(function() { $(this).val(''); });
});
}
});
</script>发布于 2014-03-03 07:25:04
尝试将input[type="password"]添加到选择器中,因此更改:
$(':text, textarea')至:
$(':text, textarea, input[type="password"]')因为*文本选择器只选择<input type="text">元素
发布于 2014-03-03 07:28:27
两个问题:
:text jQuery选择器只选择type=text (显式或隐式)的input。您必须将input[type=passsword]添加到选择器中,才能同时包含密码字段。span或div。https://stackoverflow.com/questions/22140888
复制相似问题