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

JAVASCRIPT开平方的问题。。。。。
<script language="javascript">

function move()
{
xa=window.event.clientX;
ya=window.event.clientY;
xb=Layer1.style.pixelLeft;
yb=Layer1.style.pixelTop;
x=xb;
if(xb<xa)
{
movelayer(Math.sqrt((xa-xb)(xa-xb)+(ya-yb)(ya-yb))); //注意这里。。。。。。。。。。。。。。
}
else
{
movelayer1();
}
}
function movelayer1()
{
if(x>=xa)
{
y=((ya-yb)*(x-xb))/(xa-xb)+yb;
Layer1.style.pixelLeft=x;
Layer1.style.pixelTop=y;
x--;
setTimeout('movelayer1()',100);
}
}

function movelayer(changdu)
{
if(x<=xa)
{
document.write(changdu);
//y=((ya-yb)*(x-xb))/(xa-xb)+yb;
//Layer1.style.pixelLeft=x;
//Layer1.style.pixelTop=y;
//x++;
//setTimeout('movelayer()',100);
}
}
</script>
<body onclick="move()">
<div id="Layer1" style="position:absolute; width:67px; height:41px; z-index:1; left: 360px; top: 230px">
<input name=i type=button onclick="javascript:location.href='mailto:wwwarden@yeah.net';" value="wwwarden@yeah.net"></div>
</body>

运行的时候上面的红色部分老是提示缺少函数。。。。。
请问那句写错了没????
这个是层根据鼠标点击移动的效果,只是他向各个方向移动的速度很不平均。。。我想写个能够平均的,但是计算开方的时候出错,,,
下面是程序的修改前的。。请大家看看。。
<script language="javascript">

function move()
{
xa=window.event.clientX;
ya=window.event.clientY;
xb=Layer1.style.pixelLeft;
yb=Layer1.style.pixelTop;
x=xb;
if(xb<xa)
{
movelayer();
}
else
{
movelayer1();
}
}
function movelayer1()
{
if(x>=xa)
{
y=((ya-yb)*(x-xb))/(xa-xb)+yb;
Layer1.style.pixelLeft=x;
Layer1.style.pixelTop=y;
x--;
setTimeout('movelayer1()',100);
}
}
function movelayer()
{
if(x<=xa)
{
y=((ya-yb)*(x-xb))/(xa-xb)+yb;
Layer1.style.pixelLeft=x;
Layer1.style.pixelTop=y;
x++;
setTimeout('movelayer()',100);
}
}
</script>
<body onclick="move()">
<div id="Layer1" style="position:absolute; width:67px; height:41px; z-index:1; left: 360px; top: 230px">
<input name=i type=button onclick="javascript:location.href='mailto:wwwarden@yeah.net';" value="wwwarden@yeah.net"></div>
</body>



------解决方案--------------------


function movelayer()
放到前面试试



== 思想重于技巧 ==
------解决方案--------------------
晕,两个运算数间运算符号....

(xa-xb)(xa-xb)+(ya-yb)(ya-yb)
------解决方案--------------------
.........

程序不同数学....怎么可能不加
------解决方案--------------------
需要加上'*',movelayer(Math.sqrt((xa-xb)*(xa-xb)+(ya-yb)*(ya-yb))