日期:2014-05-16 浏览次数:20357 次
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Page</title> <style type="text/css"> body{width:100%;height:100%;} .divNum{height:25;margin:0 ;padding:0;text-align:right;} .divBgColor{ FILTER: progid:DXImageTransform.Microsoft.Gradient(gradientType=1,startColorStr=#ff0000,endColorStr=#ffffff);/*IE6*/ background:-moz-linear-gradient(left,#ff0000,#ffffff);/*非IE6的其它*/ background:-webkit-gradient(linear, 0% 100%, 0% 0%, from(#ff0000), to(#ffffff));/*非IE6的其它*/ } </style> </head> <body> <div style="width:600px; height:auto; line-height:25px; margin:50px auto; border:1px solid #eee; padding:20px" id="divContorl"> </div> </body> <script type="text/javascript"> var colors=['red','green','yellow','blue','#eee']; var divContorl = document.getElementById("divContorl"); var maxLength = 500; function CreateDdivNum1(nums) { if(!nums || !nums.length)return; var maxNum = GetMax(nums); for(var i=0;i<nums.length;i++) { var div = document.createElement("div"); div.className="divNum divBgColor"; div.style.width=(maxLength * nums[i]/maxNum)+"px"; div.innerHTML=nums[i]; divContorl.appendChild(div); } } function CreateDdivNum2(nums) { if(!nums || !nums.length)return; var sum = GetSum(nums); var divParent = document.createElement("div"); divParent.style.width=(maxLength)+"px"; divParent.style.marginTop="20px"; for(var i=0;i<nums.length;i++) { var div = document.createElement("div"); div.className="divNum"; div.style.cssText="float:left;width:"+(maxLength * nums[i]/sum)+"px;background-color:"+colors[i]; div.innerHTML=nums[i]; divParent.appendChild(div); } divContorl.appendChild(divParent); var div=document.createElement("div"); div.style.cssText="clear:both;"; divContorl.appendChild(div); } function GetMax(nums) {