javascript入门· javascript math对象演示

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

演示一:对比大小

演示二:计算值的N次方

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

 

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

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

function pw(form){
    
var one=form.one.value;//得到文本框One的值
    var two=form.two.value;//得到文本框two的值
    var pw=Math.pow(one,two)
    alert(pw)
}

function Round(form){//弹出四舍五入的值
    alert(Math.round(form.one.value))
}

function rdm(form){
/*
Math.floor是返回任意浮点数的整数部分
Math.random 返回0和1之间的浮点数
88这个数是上限,自定义的
*/

    alert(Math.floor(Math.random() 
* 88+ 1)
}

</ script >
</ head >

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值