对于IE 10 以下版本placeholder的兼容性解决方案

<!-- 对于IE 10 以下版本placeholder的兼容性调整 -->
<!--[if lt IE 10]>
<script>
$(function(){
	
	$("input[type!='password'],textarea").bind({
		"focus":function(){
			var placeholderVal = $(this).attr("placeholder");
			var realVal = $(this).val();
			if($.trim(realVal)==placeholderVal){
				$(this).val("");
			}
		},
		"blur":function(){
			var placeholderVal = $(this).attr("placeholder");
			var realVal = $(this).val();
			if($.trim(realVal)==""){
				$(this).val(placeholderVal);
			}
		}
	});
	
	$("input[type!='password'],textarea").each(function(i,n){
		$(this).val($(this).attr("placeholder"));
	});
	
	
	$("input[type='password']").bind({
		"focus":function(){			
			var placeholderVal = $(this).attr("placeholder");
			var realVal = $(this).val();
			if($.trim(realVal)==placeholderVal){
				var copy_this = $(this).clone(true,true);
				$(copy_this).attr("type","password");
				$(copy_this).insertAfter($(this));
				$(this).remove();				
				$(copy_this).val("");
				$(copy_this).focus();
			}
		},
		"blur":function(){			
			var placeholderVal = $(this).attr("placeholder");
			var realVal = $(this).val();
			if($.trim(realVal)==""){
				var copy_this = $(this).clone(true,true);
				$(copy_this).attr("type","text");
				$(copy_this).insertAfter($(this));
				$(this).remove();				
				$(copy_this).val(placeholderVal);
			}
		}
	});
	
	$("input[type='password']").each(function(i,n){
		var placeHolderVal = $(this).attr("placeholder");
		var copy_this = $(this).clone(true,true);
		$(copy_this).attr("type","text");
		$(copy_this).insertAfter($(this));
		$(this).remove();
		$(copy_this).val(placeHolderVal);				
	});
});
</script>
<![endif]-->



继续更新,


<input type="password" id="loginPassword" placeholder="密码(6-16位字母数字)" class="width270">
	          	<input type="text" passwordMask="true" placeholder="密码(6-16位字母数字)" style="display:none;" class="width270">



<!-- 对于IE 10 以下版本placeholder的兼容性调整 -->
<!--[if lt IE 10]>
<script>
$(function(){
//文本域的事件监听
$("input[type!='password'][passwordMask!='true'],textarea").bind({
"focus":function(){
var placeholderVal = $(this).attr("placeholder");
var realVal = $(this).val();
if($.trim(realVal)==placeholderVal){
$(this).val("");
}
},
"blur":function(){
var placeholderVal = $(this).attr("placeholder");
var realVal = $(this).val();
if($.trim(realVal)==""){
$(this).val(placeholderVal);
}
}
});

//初始化除password框之外的文本域
$("input[type!='password'],textarea").each(function(i,n){
$(this).val($(this).attr("placeholder"));
});

//密码框失去焦点,显示文本框
$("input[type='password']").blur(function(){
var next = $(this).next("input[type='text'][passwordMask='true']");
var val = $(this).val();
if($.trim(val)==""){
$(next).show();
$(this).hide();
}
});

//文本框获得焦点,显示密码框
$("input[type='text'][passwordMask='true']").focus(function(){
var prev = $(this).prev("input[type='password']");
$(this).hide();
$(prev).show().focus();
});

//页面初始化密码框为文本框
$("input[type='text'][passwordMask='true']").each(function(i,n){
var prev = $(this).prev("input[type='password']");
$(prev).hide();
$(this).show();
});

});
</script>
<![endif]-->

转载于:https://my.oschina.net/ski/blog/337661

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值