- <html>
- <head>
- <title>計算公式</title>
- <meta http-equiv="pragma" content="no-cache">
- <meta http-equiv="cache-control" content="no-cache">
- <meta http-equiv="expires" content="0">
- <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
- <meta http-equiv="description" content="This is my page">
- <script type="text/javascript">
- function SumF(val){
- try{
- if(val.indexOf("+")!= -1 || val.indexOf("-")!= -1 ||
- val.indexOf("*")!= -1 || val.indexOf("/")!= -1 ||
- val.indexOf("(")!= -1 || val.indexOf(")")!= -1)
- document.getElementById("tes2").value = eval("("+val+")") ;
- }catch(err){
- txt="表達式中存在錯誤。\n\n";
- txt+="錯誤描述:" + err.description + "\n\n";
- txt+="點擊「肯定」繼續。\n\n";
- //alert(txt);
- }
- }
- </script>
- </head>
- <body>
- 計算公式:<input type="text" onkeyup="SumF(this.value);" id="tes1" name="tes1" />
- 計算結果:<input type="text" id="tes2" name="tes2" readonly="readonly"/>
- </body>
- </html>
一個網友的需求~~~作出來、瞬間感受javaScript很強大!!!javascript