日期:2014-05-16  浏览次数:20397 次

问一个数学问题
在一个Div(以下简称父亲)中有10个Div(以下简称儿子),儿子的大小是一样的,彼此的间距也是一样的
现在要求将10个儿子从左至右变大,求一算法可以得到每个儿子的大小

类似以下实例,但并不是彼此的简距,而是儿子本身的大小

□       □       □       □       □       □
得出:
□   □     □       □         □           □



------解决方案--------------------
var div=document.getElementById( "father ");
var children=div.document.getElementsByTagName( "div ");
for(var i=0;i <children.length;i++){
children[i].style.width=parseInt(children[i].style.width)+i*10;
children[i].style.height=parseInt(children[i].style.height)+i*10;
}

这样么?
------解决方案--------------------
<html>
<head>
<title> </title>
<style>
#Father div {
float: left;
margin: 5px;
border: solid 1px #000;
width: 20px;
height: 20px;
}
</style>
<script language= "JavaScript ">
function ZoomIn()
{
var father = document.getElementById( "Father ");
for(var i = 0; i < father.children.length; i++)
{
father.children[i].style.width = 20 + i * 5;
father.children[i].style.height = 20 + i * 5;
}
}
</script>
</head>
<body>
<div id= "Father ">
<div> </div>
<div> </div>
<div> </div>
<div> </div>
<div> </div>
<div> </div>
<div> </div>
<div> </div>
<div> </div>
<div> </div>
</div>
<p style= "clear:both; "> <button onclick= "ZoomIn() "> 放大 </button> </p>
</body>
</html>
------解决方案--------------------
任何递增函数都可以
设x∈[n, m] n,m的值根据定义域和实际变化情况定
采样距离△x =(m-n)/10
比如
线性函数 y = ax + b (a> 0) 等量增长
指数函数 y = x^a 越长越快
对数函数 y = ln(x) 越长越慢