事半功倍之js(四)
时间:2008-04-22 来源:傲枭
第九章 使用字符串
1.使用字符串对象
2.使用子字符串
3.连接字符串
4.格式化字符串变量
5.创建锚和链接
6.确定字符串长度
7.在字符串内搜索
8.定位字符串中的字符
9.替换字符串中的文本
10.字符串分离
第十章 使用日期和时间
1.使用Date对象
2.显示当地时间和日期
3.获得时间和日期值
4.设置时间和日期值
第十一章 使用Math对象
1. 使用Math对象
<form name=form1>
圆的半径:<input type=text name=rad><br>
圆的面积:<input type=text name=area><br>
<input type=button name=button1 value=计算圆的面积 onclick=document.form1.area.value=document.form1.rad.value*document.
form1.rad.value*Math.PI>
</form>
2.生成随机数
3.使用平方根
<form name=form1>
value:<input type=text name=va1><br>
平方根<input type=text name=sqrt><br>
<input type=button name=button1 value=计算平方根
onclick="document.form1.sqrt.value=Math.sqrt(document.form1.va1.value)">
</form>
4.数字的舍入
<form name=form1>
输入<input type=text name=val><br>
舍入的结果<input type=text name=round><br>
<input type=button name=button1 value=计算结果 onclick=document.form1.round.value=Math.round(document.form1.val.value)>
</form>
5.乘方运算
<form name=form1>
底数<input type=text name=val><br>
指数<input type=text name=power><br>
幂<input type=text name=result><br>
<input type=button name=button1 value=计算结果 onclick="document.form1.result.value=Math.pow (document.form1.val.value,document.form1.power.value)">
</form>
6.发现最小值和最大值
<form name=form1>
数字1<input type=text name=val1><br>
数字2<input type=text name=val2><br>
最小值<input type=text name=min><br>
最大值<input type=text name=max><br>
数字1<input type=button value=计算 onclick="document.form1.min.value=Math.min (document.form1.val1.value,document.form1.val2.value);document.form1.
max.value= Math.max(document.form1.val1.value,document.form1.val2.value)">
</form>