介绍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
热门推荐
10 生日的祝福语 文案简短
11 睡觉祝福语女生文案简短
12 生日酒宴诗句祝福语简短
13 结婚等待吃饭祝福语简短
14 2026年祝福语大全简短
15 女性的生日祝福语简短
16 希望生产顺利祝福语简短
17 食堂阿姨退休祝福语简短
18 给红包祝福语简短搞笑