JavaScript abs()方法
- abs()Math对象的方法返回数字的绝对值。
语法
Math.abs(x)
- X是必填的数字
JavaScript Math.abs方法示例
<!DOCTYPE html>
<html>
<body>
<h3 style="background-color:Red">abs() 方法 示例</h3>
<p id="demo">查看绝对值</p>
<button onclick="myFunction()">Click On</button>
<script type="text/javascript">
function myFunction() {
var a = Math.abs(9.25);
console.log("First absolute Value : " + a);
var b = Math.abs(-3);
console.log("<br />second absolute Value : " + b);
var c = Math.abs(null);
console.log("<br />Third absolute Value : " + c);
var d = Math.abs("Welcome");
console.log("<br />Fourth absolute Value : " + d);
}
</script>
</body>
</html>
日期:2020-04-18 01:09:17 来源:oir作者:oir
