在上节string对象上我瞎扯了几句math的数学函数,希望没有吓倒你哦,呵呵,其实我们要用的很少了,一般那些什么切,什么弦我们是不用的,所以我也没有打算演示哦,这里我们把常用的几个作下!

演示一:对比大小

演示二:计算值的N次方

演示三: 四舍五入取值 (值是整数哈)

 

演示四:生成0-88之间的随机数字

javascript入门· javascript math对象演示_htmljavascript入门· javascript math对象演示_四舍五入_02<%javascript入门· javascript math对象演示_文本框_03@LANGUAGE="JAVASCRIPT" CODEPAGE="936"%>
javascript入门· javascript math对象演示_四舍五入_04
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
javascript入门· javascript math对象演示_四舍五入_04
<html xmlns="http://www.w3.org/1999/xhtml">
javascript入门· javascript math对象演示_四舍五入_04
<head>
javascript入门· javascript math对象演示_四舍五入_04
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
javascript入门· javascript math对象演示_四舍五入_04
<title>javascript math对象演示</title>
javascript入门· javascript math对象演示_htmljavascript入门· javascript math对象演示_四舍五入_02
<script language="javascript">javascript入门· javascript math对象演示_文本框_03
javascript入门· javascript math对象演示_数学函数_12javascript入门· javascript math对象演示_数学函数_13
function mx(form)javascript入门· javascript math对象演示_文本框_03{//对比大小
javascript入门· javascript math对象演示_数学函数_15
    var one=form.one.value;//得到文本框One的值
javascript入门· javascript math对象演示_数学函数_15
    var two=form.two.value;//得到文本框two的值
javascript入门· javascript math对象演示_数学函数_15
    var mx=Math.max(one,two)//利用Math.max()函数对比两个值,并把对比后大的那个值赋给变量mx
javascript入门· javascript math对象演示_数学函数_15
    alert("大的数是"+mx);//弹出提示,大的值
javascript入门· javascript math对象演示_javascript_19
}

javascript入门· javascript math对象演示_数学函数_12javascript入门· javascript math对象演示_数学函数_13
function pw(form)javascript入门· javascript math对象演示_文本框_03{
javascript入门· javascript math对象演示_数学函数_15    
var one=form.one.value;//得到文本框One的值
javascript入门· javascript math对象演示_数学函数_15
    var two=form.two.value;//得到文本框two的值
javascript入门· javascript math对象演示_数学函数_15
    var pw=Math.pow(one,two)
javascript入门· javascript math对象演示_数学函数_15    alert(pw)
javascript入门· javascript math对象演示_javascript_19}

javascript入门· javascript math对象演示_数学函数_12javascript入门· javascript math对象演示_数学函数_13
function Round(form)javascript入门· javascript math对象演示_文本框_03{//弹出四舍五入的值
javascript入门· javascript math对象演示_数学函数_15
    alert(Math.round(form.one.value))
javascript入门· javascript math对象演示_javascript_19}

javascript入门· javascript math对象演示_数学函数_12javascript入门· javascript math对象演示_数学函数_13
function rdm(form)javascript入门· javascript math对象演示_文本框_03{
javascript入门· javascript math对象演示_数学函数_12javascript入门· javascript math对象演示_数学函数_13
/**//*
javascript入门· javascript math对象演示_数学函数_15Math.floor是返回任意浮点数的整数部分
javascript入门· javascript math对象演示_数学函数_15Math.random 返回0和1之间的浮点数
javascript入门· javascript math对象演示_数学函数_1588这个数是上限,自定义的
javascript入门· javascript math对象演示_javascript_19
*/

javascript入门· javascript math对象演示_数学函数_15    alert(Math.floor(Math.random() 
* 88+ 1)
javascript入门· javascript math对象演示_html_43}

javascript入门· javascript math对象演示_四舍五入_04
</script>
javascript入门· javascript math对象演示_四舍五入_04
</head>
javascript入门· javascript math对象演示_四舍五入_04
javascript入门· javascript math对象演示_四舍五入_04
<body>
javascript入门· javascript math对象演示_四舍五入_04
<p>在上节string对象上我瞎扯了几句math的数学函数,希望没有吓倒你哦,呵呵,其实我们要用的很少了,一般那些什么切,什么弦我们是不用的,所以我也没有打算演示哦,这里我们把常用的几个作下!</p>
javascript入门· javascript math对象演示_四舍五入_04
<p><strong>演示一:对比大小</strong></p>
javascript入门· javascript math对象演示_四舍五入_04
<form id="form1" name="form1" onsubmit="return false">
javascript入门· javascript math对象演示_四舍五入_04  
<input type="text" name="one" />
javascript入门· javascript math对象演示_四舍五入_04  
<input type="text" name="two" />
javascript入门· javascript math对象演示_四舍五入_04  
<input type="submit" name="Submit" value="提交" onclick="mx(this.form)" />
javascript入门· javascript math对象演示_四舍五入_04
</form>
javascript入门· javascript math对象演示_四舍五入_04
<p><strong>演示二:计算值的N次方</strong></p>
javascript入门· javascript math对象演示_四舍五入_04
<form id="form2" name="form2" onsubmit="return false">
javascript入门· javascript math对象演示_四舍五入_04  
<input type="text" name="one" />
javascript入门· javascript math对象演示_四舍五入_04  
<input type="text" name="two" />
javascript入门· javascript math对象演示_四舍五入_04  
<input type="submit" name="Submit2" value="提交" onclick="pw(this.form)" />
javascript入门· javascript math对象演示_四舍五入_04
</form>
javascript入门· javascript math对象演示_四舍五入_04
<p><strong>演示三: 四舍五入取值 </strong>(值是整数哈)</p>
javascript入门· javascript math对象演示_四舍五入_04
<form id="form2" name="form2" onsubmit="return false">
javascript入门· javascript math对象演示_四舍五入_04  
<input type="text" name="one" />
javascript入门· javascript math对象演示_四舍五入_04  
<input type="submit" name="Submit2" value="提交" onclick="Round(this.form)" />
javascript入门· javascript math对象演示_四舍五入_04
</form>
javascript入门· javascript math对象演示_四舍五入_04
</p>
javascript入门· javascript math对象演示_四舍五入_04
<p><strong>演示四:生成0-88之间的随机数字</strong></p>
javascript入门· javascript math对象演示_四舍五入_04
<form id="form3" name="form3" onsubmit="return false">
javascript入门· javascript math对象演示_四舍五入_04  
<input type="submit" name="Submit3" value="提交" onclick="rdm(this.form)" />
javascript入门· javascript math对象演示_四舍五入_04
</form>
javascript入门· javascript math对象演示_四舍五入_04
<p>&nbsp;</p>
javascript入门· javascript math对象演示_四舍五入_04
</body>
javascript入门· javascript math对象演示_四舍五入_04
</html>
javascript入门· javascript math对象演示_四舍五入_04
网站计数器