首页 > 其他 > 详细

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

时间:2014-10-27 12:56:48      阅读:277      评论:0      收藏:0      [点我收藏+]
<!-- 对于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]-->




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

原文:http://my.oschina.net/ski/blog/337661

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