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

时间:2014-10-27 12:56:58   收藏:0   阅读:188
<!-- 对于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]-->




评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!