jQuery模拟placeholder属性
一.概述
在使用HTML的input元素时,经常会用到placeholder属性。但是IE8不支持这个placeholder属性,有点悲催,只能使用js来模拟这个placeholder了
二.模拟placeholder的js代码
if(!$.support.placeholder) { var els = $('input[placeholder],textarea[placeholder]'); els.each(function(i, el) { el = $(el); var defValue = el.attr('placeholder'), defColor = el.css('color'); el.bind('focus',function() { if(this.value === '' || this.value === defValue) { $(this).css('color', defColor); this.value = ''; } }); el.bind('blur',function() { if(this.value === '' || this.value === defValue) { $(this).css('color','#aaa'); this.value = defValue; } }); el.triggerHandler('blur'); el.closest('form').submit(function(){ var val = el.val(); if(val === defValue){ el.val(''); } }); }); }
相关推荐
EdwardSiCong 2020-11-23
85477104 2020-11-17
hhanbj 2020-11-17
81427005 2020-11-11
seoppt 2020-09-13
honeyth 2020-09-13
WRITEFORSHARE 2020-09-13
84483065 2020-09-11
momode 2020-09-11
85477104 2020-08-15
83510998 2020-08-08
82550495 2020-08-03
tthappyer 2020-08-03
84901334 2020-07-28
tthappyer 2020-07-25
TONIYH 2020-07-22
tztzyzyz 2020-07-20
83510998 2020-07-18
81463166 2020-07-17