这是我的代码:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<script type="text/JavaScript">
function addChar(input, character) {
if(input.value == null || input.value == "0")
input.value = character
else
input.value += character
}
//Yay factorial stuff!!!!!! :)
function factorial(num){
if (num < 0) {
return -1;
}
else if (num == 0) {
return 1;
}
else {
return (num * factorial(num - 1));
}
}
//factorial crap :(
function factorialize(form) {
form.display.value = factorial(form.display.value);
}
//even crappier factorials
function percent(num){
if (num < 0) {
return NaN;
}
else {
return (num / 100);
}
}
//above is percent stuff
function percentalize(form) {
form.display.value = percent(form.display.value);
}
//above is also percent stuff
function sinh(form) {
form.display.value = Math.sinh(form.display.value);
}
function tanh(form) {
form.display.value = Math.tanh(form.display.value);
}
function acosh(form) {
form.display.value = Math.acosh(form.display.value);
}
function asinh(form) {
form.display.value = Math.asinh(form.display.value);
}
function atanh(form) {
form.display.value = Math.atanh(form.display.value);
}
function abs(form) {
form.display.value = Math.abs(form.display.value);
}
function trunc(form) {
form.display.value = Math.trunc(form.display.value);
}
function log10(form) {
form.display.value = Math.log10(form.display.value);
}
function log1p(form) {
form.display.value = Math.log1p(form.display.value);
}
function log2(form) {
form.display.value = Math.log2(form.display.value);
}
function ceil(form) {
form.display.value = Math.ceil(form.display.value);
}
function round(form) {
form.display.value = Math.round(form.display.value);
}
function floor(form) {
form.display.value = Math.floor(form.display.value);
}
function cos(form) {
form.display.value = Math.cos(form.display.value);
}
function tan(form) {
form.display.value = Math.tan(form.display.value);
}
function sin(form) {
form.display.value = Math.sin(form.display.value);
}
function acos(form) {
form.display.value = Math.acos(form.display.value);
}
function asin(form) {
form.display.value = Math.asin(form.display.value);
}
function atan(form) {
form.display.value = Math.atan(form.display.value);
}
function sqrt(form) {
form.display.value = Math.sqrt(form.display.value);
}
function tesseractroot(form) {
form.display.value = Math.sqrt(Math.sqrt(form.display.value));
}
function cbrt(form) {
form.display.value = Math.cbrt(form.display.value);
}
function ln(form) {
form.display.value = Math.log(form.display.value);
}
function exp(form) {
form.display.value = Math.exp(form.display.value);
}
function random(form) {
form.display.value = Math.random(form.display.value);
}
function deleteChar(input) {
input.value = input.value.substring(0, input.value.length - 1)
}
function changeSign(input) {
if(input.value.substring(0, 1) == "-")
input.value = input.value.substring(1, input.value.length)
else
input.value = "-" + input.value
}
function compute(form) {
form.display.value = eval(form.display.value)
}
function square(form) {
form.display.value = eval(form.display.value) * eval(form.display.value)
}
function cube(form) {
form.display.value = eval(form.display.value) * eval(form.display.value) * eval(form.display.value)
}
function tesseract(form) {
form.display.value = eval(form.display.value) * eval(form.display.value) * eval(form.display.value) * eval(form.display.value)
}
function oneoverx(form) {
form.display.value = eval(1) / eval(form.display.value)
}
// begin memory functions
var memory = 0;
function memoryshow (el) {
el.form.display.value = memory;
el.form.memoryindicator.value = memory;
}
function clearmemory (el) {
memory = 0;
el.form.memoryindicator.value = memory;
}
function memoryset (el) {
memory = el.form.display.value;
el.form.memoryindicator.value = memory;
}
function memoryadd (el) {
memory = parseInt (el.form.display.value) + parseInt (memory);
el.form.memoryindicator.value = memory;
}
//vars
var A = 0;
function Ashow (el) {
el.form.display.value = A;
el.form.memoryindicator.value = A;
}
function Aset (el) {
A = el.form.display.value;
el.form.memoryindicator.value = A;
}
var B = 0;
function Bshow (el) {
el.form.display.value = B;
el.form.memoryindicator.value = B;
}
function Bset (el) {
B = el.form.display.value;
el.form.memoryindicator.value = B;
}
var C = 0;
function Cshow (el) {
el.form.display.value = C;
el.form.memoryindicator.value = C;
}
function Cset (el) {
C = el.form.display.value;
el.form.memoryindicator.value = C;
}
var D = 0;
function Dshow (el) {
el.form.display.value = D;
el.form.memoryindicator.value = D;
}
function Dset (el) {
D = el.form.display.value;
el.form.memoryindicator.value = D;
}
var E = 0;
function Eshow (el) {
el.form.display.value = E;
el.form.memoryindicator.value = E;
}
function Eset (el) {
E = el.form.display.value;
el.form.memoryindicator.value = E;
}
//checknum stuff
function checkNum(str) {
for (var i = 0; i < str.length; i++) {
var ch = str.substring(i, i+1)
if (ch < "0" || ch > "9") {
if (ch != "/" && ch != "*" && ch != "+" && ch != "-" && ch != "."
&& ch != "(" && ch!= ")") {
alert("invalid entry!")
return false
}
}
}
return true
}
</script>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="content-type">
<title>A Fab Calculator</title>
</head>
<body style="background-color: white; color: rgb(0, 0, 0);"
alink="#ee0000" link="#0000ee" vlink="#551a8b">
<br>
<div style="text-align: center; color: rgb(153, 51, 153);">
<h1><span style="color: red;"></span></h1>
<h1><span style="color: red;">C</span><span
style="color: rgb(255, 153, 0);">A</span><span
style="color: yellow;">L</span><span
style="color: rgb(51, 255, 51);">C</span><span
style="color: rgb(51, 255, 255);">U</span><span
style="color: rgb(51, 153, 153);">L</span><span
style="color: rgb(51, 51, 255);">A</span><span
style="color: rgb(102, 51, 255);">T</span><span
style="color: rgb(255, 153, 255);">O<span
style="color: rgb(204, 102, 204);">R</span></span><span
style="color: rgb(102, 51, 102);"><span
style="color: rgb(153, 51, 153);">Z</span></span><span
style="color: black;"></span></h1>
<h1><span style="color: black;"></span></h1>
</div>
<p style="background-color: white;">My fantasticly
faboulous scientific
calculator with funky functions. Work in progress</p>
<form style="background-color: white;" name="calculator">
<table style="width: 256px; height: 216px;" align="center"
border="2" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td
style="text-align: center; background-color: rgb(204, 204, 204);"
colspan="5"><input name="display" value="0"
size="28" maxlength="24"></td>
</tr>
<tr>
<td style="background-color: rgb(204, 204, 204);"
align="center"><input value=" exp "
onclick="if (checkNum(this.form.display.value)) { exp(this.form) }"
type="button"></td>
<td style="background-color: rgb(204, 204, 204);"
align="center"><input value=" 7 "
onclick="addChar(this.form.display, '7')" type="button"></td>
<td style="background-color: rgb(204, 204, 204);"
align="center"><input value=" 8 "
onclick="addChar(this.form.display, '8')" type="button"></td>
<td style="background-color: rgb(204, 204, 204);"
align="center"><input value=" 9 "
onclick="addChar(this.form.display, '9')" type="button"></td>
<td style="background-color: rgb(204, 204, 204);"
align="center"><input value=" / "
onclick="addChar(this.form.display, '/')" type="button"></td>
</tr>
<tr>
<td style="background-color: rgb(204, 204, 204);"
align="center"><input value=" ln "
onclick="if (checkNum(this.form.display.value)) { ln(this.form) }"
type="button"></td>
<td style="background-color: rgb(204, 204, 204);"
align="center"><input value=" 4 "
onclick="addChar(this.form.display, '4')" type="button"></td>
<td style="background-color: rgb(204, 204, 204);"
align="center"><input value=" 5 "
onclick="addChar(this.form.display, '5')" type="button"></td>
<td style="background-color: rgb(204, 204, 204);"
align="center"><input value=" 6 "
onclick="addChar(this.form.display, '6')" type="button"></td>
<td style="background-color: rgb(204, 204, 204);"
align="center"><input value=" * "
onclick="addChar(this.form.display, '*')" type="button"></td>
</tr>
<tr>
<td style="background-color: rgb(204, 204, 204);"
align="center"><input value=" sqrt "
onclick="if (checkNum(this.form.display.value)) { sqrt(this.form) }"
type="button"></td>
<td style="background-color: rgb(204, 204, 204);"
align="center"><input value=" 1 "
onclick="addChar(this.form.display, '1')" type="button"></td>
<td style="background-color: rgb(204, 204, 204);"
align="center"><input value=" 2 "
onclick="addChar(this.form.display, '2')" type="button"></td>
<td style="background-color: rgb(204, 204, 204);"
align="center"><input value=" 3 "
onclick="addChar(this.form.display, '3')" type="button"></td>
<td style="background-color: rgb(204, 204, 204);"
align="center"><input value=" - "
onclick="addChar(this.form.display, '-')" type="button"></td>
</tr>
<tr>
<td style="background-color: rgb(204, 204, 204);"
align="center"><input value=" sq "
onclick="if (checkNum(this.form.display.value)) { square(this.form) }"
type="button"></td>
<td style="background-color: rgb(204, 204, 204);"
align="center"><input value=" 0 "
onclick="addChar(this.form.display, '0')" type="button"></td>
<td style="background-color: rgb(204, 204, 204);"
align="center"><input value=" . "
onclick="addChar(this.form.display, '.')" type="button"></td>
<td style="background-color: rgb(204, 204, 204);"
align="center"><input value=" +/- "
onclick="changeSign(this.form.display)" type="button"></td>
<td style="background-color: rgb(204, 204, 204);"
align="center"><input value=" + "
onclick="addChar(this.form.display, '+')" type="button"></td>
</tr>
<tr>
<td style="background-color: rgb(204, 204, 204);"
align="center"><input value=" ( "
onclick="addChar(this.form.display, '(')" type="button"></td>
<td style="background-color: rgb(204, 204, 204);"
align="center"><input value="cos"
onclick="if (checkNum(this.form.display.value)) { cos(this.form) }"
type="button"></td>
<td style="background-color: rgb(204, 204, 204);"
align="center"><input value=" sin"
onclick="if (checkNum(this.form.display.value)) { sin(this.form) }"
type="button"></td>
<td style="background-color: rgb(204, 204, 204);"
align="center"><input value=" tan"
onclick="if (checkNum(this.form.display.value)) { tan(this.form) }"
type="button"></td>
<td
style="background-color: rgb(204, 204, 204); text-align: center;"><input
value=" ) " onclick="addChar(this.form.display, ')')"
type="button"></td>
</tr>
<tr>
<td style="background-color: rgb(204, 204, 204);"
align="center"><input value=" clear "
onclick="this.form.display.value = 0 " type="button"></td>
<td style="background-color: rgb(204, 204, 204);"
colspan="2" align="center"><input
value=" backspace " onclick="deleteChar(this.form.display)"
type="button"></td>
<td style="background-color: rgb(204, 204, 204);"
align="center"><input value=" Π "
onclick="this.form.display.value = 3.141592653589793"
type="button"></td>
<td style="background-color: rgb(204, 204, 204);"
align="center"><input value="=" name="enter"
onclick="if (checkNum(this.form.display.value)) { compute(this.form) }"
type="button"></td>
</tr>
<tr>
<td style="background-color: rgb(204, 204, 204);"
align="center"><input value=" abs "
onclick="if (checkNum(this.form.display.value)) { abs(this.form) }"
type="button"></td>
<td style="background-color: rgb(204, 204, 204);"
align="center"><input value=" atan"
onclick="if (checkNum(this.form.display.value)) { atan(this.form) }"
type="button"></td>
<td style="background-color: rgb(204, 204, 204);"
align="center"><input value=" asin"
onclick="if (checkNum(this.form.display.value)) { asin(this.form) }"
type="button"></td>
<td style="background-color: rgb(204, 204, 204);"
align="center"><input value=" atan"
onclick="if (checkNum(this.form.display.value)) { atan(this.form) }"
type="button"></td>
<td style="background-color: rgb(204, 204, 204);"
align="center"><input value=" floor "
onclick="if (checkNum(this.form.display.value)) { floor(this.form) }"
type="button"></td>
</tr>
<tr>
<td style="background-color: rgb(204, 204, 204);"
align="center"><input value=" random "
onclick="if (checkNum(this.form.display.value)) { random(this.form) }"
type="button"></td>
<td style="background-color: rgb(204, 204, 204);"
align="center"><input value=" ceil "
onclick="if (checkNum(this.form.display.value)) { ceil(this.form) }"
type="button"></td>
<td style="background-color: rgb(204, 204, 204);"
align="center"><input value=" round "
onclick="if (checkNum(this.form.display.value)) { round(this.form) }"
type="button"></td>
<td style="background-color: rgb(204, 204, 204);"
align="center"><input value=" cbrt "
onclick="if (checkNum(this.form.display.value)) { cbrt(this.form) }"
type="button"></td>
<td style="background-color: rgb(204, 204, 204);"
align="center"><input value=" cube "
onclick="if (checkNum(this.form.display.value)) { cube(this.form) }"
type="button"></td>
</tr>
<tr>
<td style="background-color: rgb(204, 204, 204);"
align="center"><input value=" sinh "
onclick="if (checkNum(this.form.display.value)) { sinh(this.form) }"
type="button"></td>
<td style="background-color: rgb(204, 204, 204);"
align="center"><input value=" cosh"
onclick="if (checkNum(this.form.display.value)) { cosh(this.form) }"
type="button"></td>
<td style="background-color: rgb(204, 204, 204);"
align="center"><input value=" tanh "
onclick="if (checkNum(this.form.display.value)) { tanh(this.form) }"
type="button"></td>
<td style="background-color: rgb(204, 204, 204);"
align="center"><input value=" asinh "
onclick="if (checkNum(this.form.display.value)) { asinh(this.form) }"
type="button"></td>
<td style="background-color: rgb(204, 204, 204);"
align="center"><input value=" acosh "
onclick="if (checkNum(this.form.display.value)) { acosh(this.form) }"
type="button"></td>
</tr>
<tr>
<td style="background-color: rgb(204, 204, 204);"
align="center"><input value=" atanh "
onclick="if (checkNum(this.form.display.value)) { atanh(this.form) }"
type="button"></td>
<td style="background-color: rgb(204, 204, 204);"
align="center"><input value=" trunc "
onclick="if (checkNum(this.form.display.value)) { trunc(this.form) }"
type="button"></td>
<td style="background-color: rgb(204, 204, 204);"
align="center"><input value=" log10 "
onclick="if (checkNum(this.form.display.value)) { log10(this.form) }"
type="button"></td>
<td style="background-color: rgb(204, 204, 204);"
align="center"><input value=" log1p "
onclick="if (checkNum(this.form.display.value)) { log1p(this.form) }"
type="button"></td>
<td style="background-color: rgb(204, 204, 204);"
align="center"><input value=" log2 "
onclick="if (checkNum(this.form.display.value)) { log2(this.form) }"
type="button"></td>
</tr>
<tr>
<td style="background-color: rgb(204, 204, 204);"
align="center"><input value=" e "
onclick="this.form.display.value = 2.718281828459045"
type="button"></td>
<td style="background-color: rgb(204, 204, 204);"
align="center"><input value=" log10e "
onclick="this.form.display.value = 0.4342944819032518"
type="button"></td>
<td style="background-color: rgb(204, 204, 204);"
align="center"><input value=" log2e "
onclick="this.form.display.value = 1.4426950408889634"
type="button"></td>
<td style="background-color: rgb(204, 204, 204);"
align="center"><input value=" ln10 "
onclick="this.form.display.value = 2.302585092994046"
type="button"></td>
<td style="background-color: rgb(204, 204, 204);"
align="center"><input value=" ln2 "
onclick="this.form.display.value = 0.6931471805599453"
type="button"></td>
</tr>
<tr>
<td style="background-color: rgb(204, 204, 204);"
align="center"><input value=" M + "
onclick="memoryadd(this)" type="button"></td>
<td style="background-color: rgb(204, 204, 204);"
colspan="2" align="center"><input
value=" View Memory " onclick="memoryshow(this)"
type="button"></td>
<td style="background-color: rgb(204, 204, 204);"
align="center"><input value=" x = M "
onclick="memoryset(this)" type="button"></td>
<td style="background-color: rgb(204, 204, 204);"
align="center"><input value=" MC "
onclick="clearmemory(this)" type="button"></td>
</tr>
<tr>
<td style="background-color: rgb(204, 204, 204);"
colspan="1" align="center"><input value=" tess "
onclick="if (checkNum(this.form.display.value)) { tesseract(this.form) }"
type="button"></td>
<td style="background-color: rgb(204, 204, 204);"
colspan="1" align="center"><input
value=" tess root "
onclick="if (checkNum(this.form.display.value)) { tesseractroot(this.form) }"
type="button"></td>
<td style="background-color: rgb(204, 204, 204);"
colspan="1" align="center"><input value=" ! "
onclick="if (checkNum(this.form.display.value)) { factorialize(this.form) }"
type="button"></td>
<td style="background-color: rgb(204, 204, 204);"
colspan="1" align="center"><input value=" % "
onclick="if (checkNum(this.form.display.value)) { percentalize(this.form) }"
type="button"></td>
<td style="background-color: rgb(204, 204, 204);"
colspan="1" align="center"><input value=" 1 / X "
onclick="if (checkNum(this.form.display.value)) { oneoverx(this.form) }"
type="button"></td>
</tr>
<tr>
<td style="background-color: rgb(204, 204, 204);"
colspan="1" align="center"><input value=" Var A "
onclick="Ashow(this)" type="button"></td>
<td style="background-color: rgb(204, 204, 204);"
colspan="1" align="center"><input value=" Var B "
onclick="Bshow(this)" type="button"></td>
<td style="background-color: rgb(204, 204, 204);"
colspan="1" align="center"><input value=" Var C "
onclick="Cshow(this)" type="button"></td>
<td style="background-color: rgb(204, 204, 204);"
colspan="1" align="center"><input value=" Var D "
onclick="Dshow(this)" type="button"></td>
<td style="background-color: rgb(204, 204, 204);"
colspan="1" align="center"><input value=" Var E "
onclick="Eshow(this)" type="button"></td>
</tr>
<tr>
<td style="background-color: rgb(204, 204, 204);"
colspan="1" align="center"><input value=" Set A "
onclick="Aset(this)" type="button"></td>
<td style="background-color: rgb(204, 204, 204);"
colspan="1" align="center"><input value=" Set B "
onclick="Bset(this)" type="button"></td>
<td style="background-color: rgb(204, 204, 204);"
colspan="1" align="center"><input value=" Set C "
onclick="Cset(this)" type="button"></td>
<td style="background-color: rgb(204, 204, 204);"
colspan="1" align="center"><input value=" Set D "
onclick="Dset(this)" type="button"></td>
<td style="background-color: rgb(204, 204, 204);"
colspan="1" align="center"><input value=" Set E "
onclick="Eset(this)" type="button"></td>
</tr>
</tbody>
</table>
</form>
<br>
<br>
</body>
</html>
我仍然是Javascript的新手,有人可以提供有关如何进行排列和组合的想法吗?希望我的工作因子功能会有所帮助。此外,建议也会很棒。谢谢!