啥都不说了,直接上代码
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 5 <title>无标题文档</title> 6 <script type="text/javascript" src="por.js"></script> 7 </head> 8 <body> 9 <div style="padding-top:20px;"> 10 <input placeholder="请输入你的姓名" type="text" /> 11 </div> 15 </body> 16 </html>
por.js
//placeholder IE8 var _placeholderSupport = function() { var t = document.createElement("input"); t.type = "text"; return (typeof t.placeholder !== "undefined"); }(); window.onload = function() { var arrInputs = document.getElementsByTagName("input"); for (var i = 0; i < arrInputs.length; i++) { var curInput = arrInputs[i]; if (!curInput.type || curInput.type == "" || curInput.type == "text") HandlePlaceholder(curInput); } }; function HandlePlaceholder(oTextbox) { if (!_placeholderSupport) { var curPlaceholder = oTextbox.getAttribute("placeholder"); if (curPlaceholder && curPlaceholder.length > 0) { oTextbox.value = curPlaceholder; oTextbox.setAttribute("old_color", oTextbox.style.color); oTextbox.style.color = "#c0c0c0"; oTextbox.onfocus = function() { this.style.color = this.getAttribute("old_color"); if (this.value === curPlaceholder) this.value = ""; }; oTextbox.onblur = function() { if (this.value === "") { this.style.color = "#c0c0c0"; this.value = curPlaceholder; } } } } }
不适合密码框 - -
原文地址:http://www.cnblogs.com/jiaweniv/p/4918055.html
时间: 2024-10-12 09:33:23