首页 > 其他 > 详细

使IE支持placeholder

时间:2016-03-07 11:59:51      阅读:214      评论:0      收藏:0      [点我收藏+]

Html5的表单添加了许多给力的属性,其中输入框的placeholder便是很赞的属性!现代浏览器大多都支持这个属性,但IE8。。。。好吧,前端的童鞋们总会想出各种姿势对付IE的~_~

//使IE支持placeholder
	if( !(‘placeholder‘ in document.createElement(‘input‘)) ){
		$(‘input[placeholder]‘).each(function(){
			var that = $(this),
				text= that.attr(‘placeholder‘);
			if(that.val() === ""){
				that.val(text);
			}
			that.focus(function(){
				if(that.val() === text){
					that.val("");
				}
			}).blur(function(){
				if(that.val() === ""){
					that.val(text);
				}
			}).closest(‘form‘).submit(function(){
				if(that.val() === text){
					that.val(‘‘);   
				}
			});
		});
	}

 加上这一段代码,试试看,你的IE8是不是被你征服了~ 

使IE支持placeholder

原文:http://www.cnblogs.com/paul-myweb/p/5249853.html

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