今天看一本javascript的书,遇到了这个strCMD
function calc(strCMD)实在是没看明白这个strCMD是啥意思啊,另外附上代码,大婶帮忙看看,我是按照书上的打的,但是还是运行不出来,这是一个科学计算器的代码<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.
<html>
<head>
<title> ex2 </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<style>
*{font-size:12px;}
body{background-color:#C7C7C7;border-style:none;}
.button{width:50px;height:30px;}
#txt_display{width:100%;cursor:default;text-align:right;}
</style>
<script>
var calc_buttons=[0,1,2,3,4,5,6,7,8,9,".","=","+","-","*","/","AC","sin","sin","cos","tan","asin","acos","atan","ln"];
var previous_value=0,op="",start_new_input=true;
function calc(strCMD)
{
var objTxt=$("txt_display");
switch(strCMD)
{
case "sin":objTxt.value=Math.sin(objTxt.value);break;
case "cos":objTxt.value=Math.cos(objTxt.value);break;
case "tan":objTxt.value=Math.tan(objTxt.value);break;
case "asin":objTxt.value=Math.asin(objTxt.value);break;
case "acos":objTxt.value=Math.acos(objTxt.value);break;
case "atan":objTxt.value=Math.atan(objTxt.value);break;
case "ln":objTxt.value=Math.log(objTxt.value);break;
case "+":
case "-":
case "*":
case "/":
start_new_input=true;
if(op!=""&&objTxt.value!="")
{
objTxt.value=eval(previous_value+op+objTxt.value);
op=strCMD;
}
else
{op=strCMD;}
break;
case "=":
start_new_input=true;
if(op!=""&&objTxt!="")
objTxt.value=eval(previous_value+op+objTxt.value);
op="";
previous_value=0;
break;
case "AC":
start_new_input=true;
objTxt.value="0";
op="";
previous_value=0;
break;
case ".":
if(objTxt.value.indexOf(".")!=-1)break;
default:
if(start_new_input)
{
start_new_input=false;
previous_value=objTxt.value;
objTxt.value="0";
}
if(objTxt.value!="0")
{objTxt.value+=strCMD;}
else if(strCMD!="0")
{objTxt.value=strCMD;}
}
}
function write_table()
{
document.write("<table>");
document.write("<tr>");
for(var i=0;i<calc_buttons.length;i++)
{
document.write("<td><input value=\"" +calc_button[i]+"\"type=\"button\" class=\"button\" onclick=\"calc(this.value);\"></td>");
if((i+1)%5==0)
document.write("</tr><tr>");
}
document.write("</tr>");
document.write("</table>");
}
function $(str)
{return(document.getElementById(str));}
</script>
</head>
<body style="overflow:auto;">
<input id="txt_display" value="0" readonly>
<script>
write_table();
</script>
</body>
</html>