JavaScript Math 对象的参考手册

本文详细介绍了JavaScript中的Math对象,包括它的属性如PI、E等,以及常用的方法如abs、sin、sqrt等。这些属性和方法可以帮助开发者执行各种数学计算。

Math 对象

Math 对象用于执行数学任务。

使用 Math 的属性和方法的语法:

var pi_value=Math.PI;
var sqrt_value=Math.sqrt(15);

注释:Math 对象并不像 Date 和 String 那样是对象的类,因此没有构造函数 Math(),像 Math.sin() 这样的函数只是函数,不是某个对象的方法。您无需创建它,通过把 Math 作为对象使用就可以调用其所有属性和方法。

Math 对象属性

FF: Firefox, IE: Internet Explorer

属性 描述 FF IE
E 返回算术常量 e,即自然对数的底数(约等于2.718)。 1 3
LN2 返回 2 的自然对数(约等于0.693)。 1 3
LN10 返回 10 的自然对数(约等于2.302)。 1 3
LOG2E 返回以 2 为底的 e 的对数(约等于 1.414)。 1 3
LOG10E 返回以 10 为底的 e 的对数(约等于0.434)。 1 3
PI 返回圆周率(约等于3.14159)。 1 3
SQRT1_2 返回返回 2 的平方根的倒数(约等于 0.707)。 1 3
SQRT2 返回 2 的平方根(约等于 1.414)。 1 3

Math 对象方法

FF: Firefox, IE: Internet Explorer

方法 描述 FF IE
abs(x) 返回数的绝对值。 1 3
acos(x) 返回数的反余弦值。 1 3
asin(x) 返回数的反正弦值。 1 3
atan(x) 以介于 -PI/2 与 PI/2 弧度之间的数值来返回 x 的反正切值。 1 3
atan2(y,x) 返回从 x 轴到点 (x,y) 的角度(介于 -PI/2 与 PI/2 弧度之间)。 1 3
ceil(x) 对数进行上舍入。 1 3
cos(x) 返回数的余弦。 1 3
exp(x) 返回 e 的指数。 1 3
floor(x) 对数进行下舍入。 1 3
log(x) 返回数的自然对数(底为e)。 1 3
max(x,y) 返回 x 和 y 中的最高值。 1 3
min(x,y) 返回 x 和 y 中的最低值。 1 3
pow(x,y) 返回 x 的 y 次幂。 1 3
random() 返回 0 ~ 1 之间的随机数。 1 3
round(x) 把数四舍五入为最接近的整数。 1 3
sin(x) 返回数的正弦。 1 3
sqrt(x) 返回数的平方根。 1 3
tan(x) 返回角的正切。 1 3
toSource() 返回该对象的源代码。 1 -
valueOf() 返回 Math 对象的原始值。 1 4
<!doctype html> <html> <head> <meta charset="utf-8"> <title>周年贺卡</title> </head> <body> <table align="center" border="0" height="1200px" width="700px" background="http://photonj.photo.store.qq.com/psc?/V10BXA3B23yE7o/cX4Vyn98zHAGUajflo5h*GR.kC9ZMTx7iz.6cF0JYPwj4ENCZXFpLX2MAqD0bvlkiAMHA.ntW1l*r14zbNn.fA!!/b&bo=FQNhBBUDYQQRECc!&rf=mood_app" style="background-size: 100% 100%;"> <tr> <td height="20%"></td> </tr> <tr> <td height="70%"> <p align="center">亲爱的${NAME}:</p> <p align="center">您在${FIRST}年${SCEOND}月${THIRD}日入职</p> <p align="center">时至今日</p> <p align="center">${MESSAGE}</p> <center> <svg t="1656659495372" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2293" width="32" height="32"> <path d="M512 901.746939c-13.583673 0-26.122449-4.179592-37.093878-13.061225-8.881633-7.314286-225.697959-175.020408-312.424489-311.379592C133.746939 532.37551 94.040816 471.24898 94.040816 384.522449c0-144.718367 108.146939-262.269388 240.326531-262.269388 67.395918 0 131.657143 30.82449 177.632653 84.636735 45.453061-54.334694 109.191837-84.636735 177.110204-84.636735 132.702041 0 240.326531 117.55102 240.326531 262.269388 0 85.159184-37.093878 143.673469-67.395919 191.216327l-1.044898 1.567346c-86.726531 136.359184-303.542857 304.587755-312.424489 311.379592-10.44898 8.359184-22.987755 13.061224-36.571429 13.061225z" fill="#E5404F" p-id="2294" data-spm-anchor-id="a313x.7781069.0.i0"></path> </svg> </center> <br> <br> <p align="right" style="margin-right: 30px;"> XXXX&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp </p> </td> </tr> <tr> <td height="10%"></td> </tr> </table> </body> </html>
08-28
<?php $show_title="$MSG_LOGIN - $OJ_NAME"; ?> <?php include("template/$OJ_TEMPLATE/header.php");?> <div class="ui error message" id="error" hidden></div> <div class="ui middle aligned center aligned grid" style="height: 500px;" > <div class="row"> <div class="column" style="max-width: 450px"> <h2 class="ui image header"> <div class="content" style="margin-bottom: 10px; "> <?php echo $MSG_LOGIN ?> </div> </h2> <form class="ui large form" id="login" action="login.php" method="post" role="form" class="form-horizontal" onSubmit="return jsMd5();" > <div class="ui existing segment"> <div class="field"> <div class="ui left icon input"> <i class="user icon"></i> <input name="user_id" placeholder="<?php echo $MSG_USER_ID ?>" type="text" id="username"> </div> </div> <div class="field"> <div class="ui left icon input"> <i class="lock icon"></i> <input name="password" placeholder="<?php echo $MSG_PASSWORD ?>" type="password" id="password"> </div> </div> <?php if($OJ_VCODE){?> <div class="field"> <div class="ui left icon input"> <i class="lock icon"></i> <input name="vcode" placeholder="<?php echo $MSG_VCODE ?>" type="text" autocomplete=off > <img id="vcode-img" onclick="this.src='vcode.php?'+Math.random()" height="30px"> </div> </div> <?php }?> <button name="submit" type="submit" class="ui fluid large submit button" ><?php echo $MSG_LOGIN ?></button> 1,1 Top </div> <?php }?> <button name="submit" type="submit" class="ui fluid large submit button" ><?php echo $MSG_LOGIN ?></button> </div> <div class="ui error message"></div> </form> <div class="ui message"> <?php if ($OJ_REGISTER){ ?> <a href="registerpage.php"><?php echo $MSG_REGISTER ?></a>            <?php } ?> </div> </div> </div> </div> <script src="<?php echo $OJ_CDN_URL?>include/md5-min.js"></script> <script> function jsMd5(){ if($("input[name=password]").val()=="") return false; $("input[name=password]").val(hex_md5($("input[name=password]").val())); return true; } </script> <?php if ($OJ_VCODE) { ?> <script> $(document).ready(function () { $("#vcode-img").attr("src", "vcode.php?" + Math.random()); }) </script> <?php } ?> <?php include("template/$OJ_TEMPLATE/footer.php");?>
03-27
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值