1. <html> 
  2.   <head> 
  3.      
  4.     <title>计算公式</title> 
  5.      
  6.     <meta http-equiv="pragma" content="no-cache"> 
  7.     <meta http-equiv="cache-control" content="no-cache"> 
  8.     <meta http-equiv="expires" content="0">     
  9.     <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> 
  10.     <meta http-equiv="description" content="This is my page"> 
  11.     <script type="text/javascript"> 
  12.         function SumF(val){ 
  13.             try{ 
  14.                 if(val.indexOf("+")!= -1 || val.indexOf("-")!= -1 ||  
  15.                         val.indexOf("*")!= -1 || val.indexOf("/")!= -1 ||  
  16.                         val.indexOf("(")!= -1 || val.indexOf(")")!= -1)  
  17.                     document.getElementById("tes2").value = eval("("+val+")") ;    
  18.             }catch(err){   
  19.                txt="表达式中存在错误。\n\n"
  20.                txt+="错误描述:" + err.description + "\n\n";     
  21.                txt+="点击“确定”继续。\n\n";   
  22.                //alert(txt);   
  23.             }   
  24.         } 
  25.     </script> 
  26.   </head>   
  27.   <body> 
  28.     计算公式:<input type="text" onkeyup="SumF(this.value);" id="tes1" name="tes1" />   
  29.     计算结果:<input type="text" id="tes2" name="tes2" readonly="readonly"/>   
  30.    </body> 
  31. </html> 

一个网友的需求~~~做出来、瞬间感觉javaScript很强大!!!