求任意两点间的距离
X轴坐标之差的平方加上Y轴坐标之差的平方,然后对平方和开根号就是这两点间的距离
window.onload = function () {
var x1 = 0;
var y1 = 0;
var x2 = 10;
var y2 = 10;
alert(dist(x1, y1, x2, y2));
};
function dist(x1, y1, x2, y2)
{
return Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}