js实现html的placeholder属性效果

来源:互联网 发布:java 报表工具 开源 编辑:程序博客网 时间:2024/06/06 07:34

如何通过js实现html的placeholder属性效果呢

我们需要这样做:
<!DOCTYPE html><html><head><meta charset="utf-8"><title></title><script>function bl(){var a=document.getElementById("inpt");if(a.value.length<=0){a.style.color="#999999";a.value="请输入姓名";}}function fo(){var a=document.getElementById("inpt");if(a.value=="请输入姓名"){a.style.color="black";a.value="";}}</script></head><body><input style="color: #999999;" value="请输入姓名" id="inpt" type="text" onblur="bl()" onfocus="fo()" /></body></html>

自己动手试试看吧!!!奋斗
1 0