javascript的绝对值函数 : Math.abs(-1);//1 abs Method See Also Math Object Methods Applies To: Math Object Requirements Version 1 Returns the absolute value of a number. Math.abs(number) The required number argument is a numeric expression for which the absolute value is needed. Remarks The return value is the absolute value of the number argument. Example The following example illustrates the use of the abs method. function ComparePosNegVal(n) { var s; var v1 = Math.abs(n); var v2 = Math.abs(-n); if (v1 == v2) s = "The absolute values of " + n + " and " s += -n + " are identical. "; return(s); }