使IE支持placeholder

本文提供了一段JavaScript代码,用于解决IE8不支持HTML5表单属性placeholder的问题,使得该属性能够在包括IE8在内的现代浏览器中正常工作。

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是不是被你征服了~ 

转载于:https://www.cnblogs.com/paul-myweb/p/5249853.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值