<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>TEST</title>
</head>
<body>
<label>hello  world!</label>

<script type="text/javascript">
// 这个可以用$.isNumeric代替
function isNumeric(v) {
return typeof v === 'number';
}
function angle(x1, y1, x2, y2) {
if(!isNumeric(x1) || !isNumeric(y1) || !isNumeric(x2) || !isNumeric(y2)) {
throw '必须输入数字';
}
var height = y1 - y2,
width = x1 - x2;
if(width == 0) {
// 如果和y轴平行,角度为90或270
return y1 >= y2 ? 90 : 270;
} else {
var tan = Math.atan(height / width),
angle = tan * 180 / Math.PI;

return tan > 0 ? (x1 > x2 ? angle : angle + 180) : (x1 > x2 ? angle + 360 : angle + 180);
}
}

// 测试
function assert(condition, msg) {
if(!condition) {
throw msg || 'error in assert';
}
}

function angleTest() {
assert(90 == angle(2,2,2,-1));
assert(270 == angle(2,-1,2,2));
assert(45 == angle(2,2,-1,-1));
assert(225 == angle(-1,-1,2,2));
assert(135 == angle(-2,2,1,-1));
assert(315 == angle(2,-2,-1,1));
}
angleTest();
</script>
</body>
</html>