zoukankan      html  css  js  c++  java
  • 辨色器

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">  
    <html>  
    <head>  
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">  
    <title>Color Detector</title>  
    <script type="text/javascript">  
        function calc() {  
            var color = document.getElementById("color").value;  
            if(color.length!=7 && color.length!=9) {  
                alert(color.length + "The format of color is not correct!
     example: #010203 or #AA010203");  
                return;  
            }  
            var opacity = 1;  
            if(color.length==9) {  
                opacity = "0x" + color.substring(1, 3);  
                opacity = parseInt(opacity)/255;  
                color = '#' + color.substring(3, color.length);  
                  
            }  
              
            var boxstyle = document.getElementById('box').style;  
            boxstyle.background=color;  
            boxstyle.opacity =opacity;  
        }  
    </script>  
    </head>  
    <body>  
        <div id="box" style=" 150px; height: 50px; background: #e6e6e6; opacity:1"></div>  
        <input type="text" id="color" name="color" value="#e6e6e6" /> <input type="button" value="Ok" onclick="javascript: calc();"/>  
    </body>  
    </html> 
  • 相关阅读:
    10.28作业
    10.27作业
    10.26作业
    10.22作业
    10.20作业
    10.19作业
    10.16作业
    10.15作业
    10.14作业
    10.13作业
  • 原文地址:https://www.cnblogs.com/xh_Blog/p/13986346.html
Copyright © 2011-2022 走看看