打造一个 JavaScript 计算器
在网页开发中,制作一个计算器是一个常见且有趣的项目。下面我们将详细介绍如何使用 JavaScript 来创建一个功能丰富的计算器。
计算器代码全貌
<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!-- start hiding
function getPi()
{return Math.PI}
function getRandom()
{return Math.random()}
function change()
{
var temp = document.calculator.text.value;
if (temp.substring(0,1) == "-")
{document.calculator.list.value = "";
document.calculator.text.value = 0 - document.calculator.text.value * 1}
if (temp.substring(0,1) != "-")
{document.calculator.list.value ="";
document.calculator.text.value = "-" + temp.substring(0,temp.length)}
}
function recip(x)
{document.calculator.text.value = (1/(x))}
function raisePower(x)
{
var y = 0
y = prompt("What is the exponent?"
超级会员免费看
订阅专栏 解锁全文
343

被折叠的 条评论
为什么被折叠?



