zoukankan      html  css  js  c++  java
  • JS 像素数字 PHP

    输入数字:

     

    源码:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
    
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <body>
        <div>
        输入数字:<input id="txtNum" type="text" onkeyup="showNum();" value="856" />
        <div id="divNum" style="height:20px; position:relative; margin-top:5px;"></div>
        <script type="text/javascript">
        function showNum()
        {
    		var txtNum = document.getElementById('txtNum');
    		var divNum = document.getElementById('divNum');
    		if(isNaN(txtNum.value))
    		{
    			return;
    		}
    		divNum.innerHTML = '';
    		var width = Math.floor(divNum.offsetHeight / 5);
    		for(var i=0; i<txtNum.value.length; i++)
    		{
    			var index = parseInt(txtNum.value[i]);
    			var strNum = arrNum[index];
    			for(var j=0; j<strNum.length; j++)
    			{
    				if(strNum[j] == '1')
    				{
    					var div = getDiv(width);
    					div.style.left = j % 3 * width + i * width * 4;
    					div.style.top = Math.floor(j / 3) * width;
    					divNum.appendChild(div);
    				}
    			}
    		}
        }
        
        var arrNum = [
    		'111101101101111',
    		'001001001001001',
    		'111001111100111',
    		'111001111001111',
    		'101101111001001',
    		'111100111001111',
    		'111100111101111',
    		'111001001001001',
    		'111101111101111',
    		'111101111001111'
        ];
        
        function getDiv(width)
        {
    		var div = document.createElement('div');
    		div.style.width = width;
    		div.style.height = width;
    		div.style.backgroundColor = 'red';
    		div.style.position = 'absolute';
    		
    		return div;
        }
        
        showNum();
        </script>
        </div>
        </form>
    </body>
    </html>
    




    欢迎转载,转载请注明:转载自[ http://www.cnblogs.com/zjfree/ ]
  • 相关阅读:
    相对布局(下)
    html5-微格式-时间的格式
    html5-新元素新布局模板
    html5-section元素
    html5-article元素
    html5-新布局元素header,footer
    html5-基本知识小结及补充
    html5-常用的通用元素
    html5-div布局
    html5-块元素和内联元素
  • 原文地址:https://www.cnblogs.com/zjfree/p/1836795.html
Copyright © 2011-2022 走看看