标签:
直接上代码,需要引入 Jquery
$(function () { //浏览器不支持 placeholder 时才执行 if (!('placeholder' in document.createElement('input'))) { $('[placeholder]').each(function () { var $tag = $(this); //当前 input var $copy = $tag.clone(); //当前 input 的复制 $copy.css("color", "#999"); $copy.val($copy.attr('placeholder')); $copy.focus(function () { if (this.value == $copy.attr('placeholder')) { this.value = ''; this.style.color = '#000'; } }); $copy.blur(function () { if (this.value=="") { this.value = $copy.attr('placeholder'); $tag.val(""); this.style.color = '#999'; } else { $tag.val(this.value); } }); $tag.hide().after($copy.show()); //当前 input 隐藏 ,具有 placeholder 功能js的input显示 }); } });
标签:
原文地址:http://blog.csdn.net/luofeng0710/article/details/43051647