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是否是被你征服了~ 瀏覽器