计算随机数边产生平方,平方根,自然对数的小程序

来源:互联网 发布:北大青鸟网络管理 编辑:程序博客网 时间:2024/05/16 11:03
<!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=utf-8" /><title>无标题文档</title><script type="text/javascript">function newRandom(m,n){ data=Math.round(Number(m)+Math.random()*(n-m));//document.write(data);document.getElementById("input1").value=data;}function multiResult(m){if(!m) {alert("请先产生随机整数");return }var square=Math.pow(m,2);var squareRoot=Math.sqrt(m).toFixed(2);var nature=Math.log(m).toFixed(2);alert("随机整数"+data+"的计算结果"+"\n"+"平方"+"\t"+"平方根"+"\t"+"自然对数"+"\n"+square+"\t"+squareRoot+"\t"+nature);}</script></head><body>请输入要产生的随机数范围:<br /><input type="number" id="number1" />-<input type="number" id="number2" /><br /><input type="text" name="input1" id="input1" /><input type="button" value="产生随机数" onclick="newRandom(document.getElementById('number1').value,document.getElementById('number2').value)" /><input type="button" value="计算" onclick="multiResult(document.getElementById('input1').value)" /></body></html>

0 0
原创粉丝点击