码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2014-10-27 12:56:58      阅读:188      评论:0      收藏:0      [点我收藏+]

标签:io   ar   on   cti   html   as   htm   tt   type   

<!-- 对于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的兼容性解决方案

标签:io   ar   on   cti   html   as   htm   tt   type   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!