首页 > 其他 > 详细

ie9的placeholder不显示的解决办法(包含多个密码框)

时间:2015-11-17 10:48:39      阅读:245      评论:0      收藏:0      [点我收藏+]
//   兼容ie9的placeholder
function isPlaceholder(){
var input = document.createElement(‘input‘);
return ‘placeholder‘ in input;
}
if (!isPlaceholder()) {//不支持placeholder 用jquery来完成
$(document).ready(function() {
if(!isPlaceholder()){
$("input").not("input[type=‘password‘]").each(//把input绑定事件 排除password框
function(){
if($(this).val()=="" && $(this).attr("placeholder")!=""){
$(this).val($(this).attr("placeholder"));
$(this).focus(function(){
if($(this).val()==$(this).attr("placeholder")) $(this).val("");
});
$(this).blur(function(){
if($(this).val()=="") $(this).val($(this).attr("placeholder"));
});
}
});
//对password框的特殊处理1.创建一个text框 2获取焦点和失去焦点的时候切换
$("input[type=‘password‘]").each(
function() {
var pwdField = $(this);
var pwdVal = pwdField.attr(‘placeholder‘);
pwdField.after(‘<input class="login-input" type="text" value=‘+pwdVal+‘ autocomplete="off" />‘);
var pwdPlaceholder = $(this).siblings(‘.login-input‘);
pwdPlaceholder.show();
pwdField.hide();

pwdPlaceholder.focus(function(){
pwdPlaceholder.hide();
pwdField.show();
pwdField.focus();
});

pwdField.blur(function(){
if(pwdField.val() == ‘‘) {
pwdPlaceholder.show();
pwdField.hide();
}
});
})
}
});
}
// end

ie9的placeholder不显示的解决办法(包含多个密码框)

原文:http://www.cnblogs.com/vonson/p/4970867.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!