介绍JavaScript中Math.abs()方法的使用
这个方法返回一个数字的绝对值。
语法
Math.abs(x);
下面是参数的详细信息:
- x:一个数字
返回值:
- 返回一个数字的绝对值
例子:
<html>
<head>
<title>JavaScriptMathabs()Method</title>
</head>
<body>
<scripttype="text/javascript">
varvalue=Math.abs(-1);
document.write("FirstTestValue:"+value);
varvalue=Math.abs(null);
document.write("<br/>SecondTestValue:"+value);
varvalue=Math.abs(20);
document.write("<br/>ThirdTestValue:"+value);
varvalue=Math.abs("string");
document.write("<br/>FourthTestValue:"+value);
</script>
</body>
</html>
这将产生以下结果:
FirstTestValue:1 SecondTestValue:0 ThirdTestValue:20 FourthTestValue:NaN
热门推荐
6 保研的祝福语简短
10 年轻20岁祝福语简短
11 朋友结婚祝福语信息简短
12 女孩婚礼贺卡祝福语简短
13 30段点歌简短祝福语
14 虎年春节祝福语图文简短
15 写给后妈祝福语大全简短
16 简短回复生日祝福语
17 校长送毕业祝福语简短
18 毕业立体贺卡祝福语简短