zoukankan      html  css  js  c++  java
  • HTML5 新属性placeholder 兼容ie

     啥都不说了,直接上代码

     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

    It's my whole life!
  • 相关阅读:
    Mycat之按照时间进行分片
    Mysql binlog解析器
    字体属性和文本属性总结
    css选择器
    CSS的三种引入方式
    CSS样式语法
    应用程序与数据库结合使用的三种方式
    存储过程
    子查询
    多表查询
  • 原文地址:https://www.cnblogs.com/jiaweniv/p/4918055.html
Copyright © 2011-2022 走看看