我已经实现了以下脚本来在 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>
最佳答案
尝试添加input[type="password"]
到您的选择器,因此更改:
$(':text, textarea')
至:
$(':text, textarea, input[type="password"]')
自 :text selector 仅选择<input type="text">
元素
关于javascript - 占位符未在 IE 中显示密码字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22140888/