廣告廣告
  加入我的最愛 設為首頁 風格修改
首頁 首尾
 手機版   訂閱   地圖  簡體 
您是第 2692 個閱讀者
 
發表文章 發表投票 回覆文章
  可列印版   加為IE收藏   收藏主題   上一主題 | 下一主題   
水玲瓏
數位造型
個人文章 個人相簿 個人日記 個人地圖
社區建設獎 特殊貢獻獎
路人甲
級別: 路人甲 該用戶目前不上站
推文 x0 鮮花 x162
分享: 轉寄此文章 Facebook Plurk Twitter 複製連結到剪貼簿 轉換為繁體 轉換為簡體 載入圖片
推文 x0
[JScript][教學] 線上計算機
http://home.pchome.com.tw/kin...h504/999.htm

以下為計算機語法

複製程式
 
          <!-------JavaScript收集區 精緻計算機_開始-------->
<form name="Keypad" action>

<head>
<style type="text/css">
<!--
td {  font: 9pt "新細明體"; color: #FFFFFF}
.Button {  font: 9pt "新細明體"; color: #FFFFFF; background: #999999; margin: 4px 4px; width: 40px; height: 20px; border-color: #CCCCCC #333333 #333333 #CCCCCC; border-top-width: 2px; border-right-width: 2px; border-bottom-width: 2px; border-left-width: 2px}
.text_input {  font: 9pt "Verdana", "Arial", "Helvetica", "sans-serif"; color: #000000; background: #CCCCCC; text-align: right}
a {  font: 9pt "新細明體"; color: #FFFFFF}
-->
</style>
</head>

  <table border="1" width="249" height="30" cellpadding="0" cellspacing="1" bordercolorlight="#CCCCCC" bordercolordark="#999999" bordercolor="#CCCCCC" bgcolor="#666666">
    <tr>
      <td colspan="4" align="middle"><input name="ReadOut" type="Text" size="30" value="0" width="100%" class="text_input"></td>
      <td width="0"> </td>
      <td width="50"><input name="btnClear" type="Button" value="  C  " onclick="Clear()" class="Button"></td>
      <td><input name="btnClearEntry2" type="Button" value=" CE " onClick="ClearEntry()" class="Button"></td>
    </tr>
    <tr>
      <td width="50"><input name="btnSeven" type="Button" value="  7  " onclick="NumPressed(7)" class="Button"></td>
      <td width="50"><input name="btnEight" type="Button" value="  8  " onclick="NumPressed(8)" class="Button"></td>
      <td width="50"><input name="btnNine" type="Button" value="  9  " onclick="NumPressed(9)" class="Button"></td>
      <td width="50"><input name="btnHex" type="Button" value="HEX" onClick="hexchange()" class="Button"></td>
      <td width="0"> </td>
      <td width="50"><input name="btnNeg" type="Button" value=" +/- " onclick="Neg()" class="Button"></td>
      <td><input name="btnPercent" type="Button" value=" % " onClick="Percent()" class="Button"></td>
    </tr>
    <tr>
      <td width="50"><input name="btnFour" type="Button" value="  4  " onclick="NumPressed(4)" class="Button"></td>
      <td width="50"><input name="btnFive" type="Button" value="  5  " onclick="NumPressed(5)" class="Button"></td>
      <td width="50"><input name="btnSix" type="Button" value="  6  " onclick="NumPressed(6)" class="Button"></td>
      <td width="50"><input name="btnClearEntry222" type="Button" value="OCT" onClick="octchange()" class="Button"></td>
      <td width="0"> </td>
      <td align="middle" width="50"><input name="btnPlus" type="Button" value="  +  " onclick="Operation('+')" class="Button"></td>
      <td align="middle"><input name="btnMinus" type="Button" value="  -   " onClick="Operation('-')" class="Button"></td>
    </tr>
    <tr>
      <td width="50"><input name="btnOne" type="Button" value="  1  " onclick="NumPressed(1)" class="Button"></td>
      <td width="50"><input name="btnTwo" type="Button" value="  2  " onclick="NumPressed(2)" class="Button"></td>
      <td width="50"><input name="btnThree" type="Button" value="  3  " onclick="NumPressed(3)" class="Button"></td>
      <td width="50"><input name="btnClearEntry23" type="Button" value="BIN" onClick="binchange()" class="Button"></td>
      <td width="0"> </td>
      <td align="middle" width="50"><input name="btnMultiply" type="Button" value="  *  " onclick="Operation('*')" class="Button"></td>
      <td align="middle"><input name="btnDivide" type="Button" value="  /   " onClick="Operation('/')" class="Button"></td>
    </tr>
    <tr>
      <td width="50"><input name="btnZero" type="Button" value="  0  " onclick="NumPressed(0)" class="Button"></td>
      <td width="50"><input name="btnDecimal" type="Button" value="   .  " onclick="Decimal()" class="Button"></td>
      <td colspan="4">
        <div align="center">
             
        </div>  
      </td>  
      <td colspan="5"><input name="btnEquals" type="Button" value="  =  " onClick="Operation('=')" class="Button"></td>  
    </tr>  
  </table>  
</form>  
<script LANGUAGE="JavaScript">  
var FKeyPad = document.Keypad;  
var Accum = 0;  
var FlagNewNum = false;  
var PendingOp = "";  
function NumPressed (Num) {  
if (FlagNewNum) {  
FKeyPad.ReadOut.value  = Num;  
FlagNewNum = false;  
   }  
else {  
if (FKeyPad.ReadOut.value == "0")  
FKeyPad.ReadOut.value = Num;  
else  
FKeyPad.ReadOut.value += Num;  
   }  
}  
function Operation (Op) {  
var Readout = FKeyPad.ReadOut.value;  
if (FlagNewNum && PendingOp != "=");  
else  
{  
FlagNewNum = true;  
if ( '+' == PendingOp )  
Accum += parseFloat(Readout);  
else if ( '-' == PendingOp )  
Accum -= parseFloat(Readout);  
else if ( '/' == PendingOp )  
Accum /= parseFloat(Readout);  
else if ( '*' == PendingOp )  
Accum *= parseFloat(Readout);  
else  
Accum = parseFloat(Readout);  
FKeyPad.ReadOut.value = Accum;  
PendingOp = Op;  
   }  
}  
function Decimal () {  
var curReadOut = FKeyPad.ReadOut.value;  
if (FlagNewNum) {  
curReadOut = "0.";  
FlagNewNum = false;  
   }  
else  
{  
if (curReadOut.indexOf(".") == -1)  
curReadOut += ".";  
   }  
FKeyPad.ReadOut.value = curReadOut;  
}  
function ClearEntry () {  
FKeyPad.ReadOut.value = "0";  
FlagNewNum = true;  
}  
function Clear () {  
Accum = 0;  
PendingOp = "";  
ClearEntry();  
}  
function Neg () {  
FKeyPad.ReadOut.value = parseFloat(FKeyPad.ReadOut.value) * -1;  
}  
function Percent () {  
FKeyPad.ReadOut.value = (parseFloat(FKeyPad.ReadOut.value) / 100) * parseFloat(Accum);  
}  
function hexchange()  
{  
var hex,dec;  
dec = parseFloat(FKeyPad.ReadOut.value);  
hex = dec.toString(16);  
window.alert("該十進制數轉成十六進制數為:"+ hex);  
}  
function octchange()  
{  
var oct,dec;  
dec = parseFloat(FKeyPad.ReadOut.value);  
oct = dec.toString(8);  
window.alert("該十進制數轉成八進制數為:"+ oct);  
}  
function binchange()  
{  
var bin,dec;  
dec = parseFloat(FKeyPad.ReadOut.value);  
bin = dec.toString(2);  
window.alert("該十進制數轉成二進制數為:"+ bin);  
}  
</script>  
          <!-------JavaScript收集區 精緻計算機_END-------->



獻花 x0 回到頂端 [樓 主] From:台灣中華電信 | Posted:2005-02-24 00:04 |

首頁  發表文章 發表投票 回覆文章
Powered by PHPWind v1.3.6
Copyright © 2003-04 PHPWind
Processed in 0.058257 second(s),query:15 Gzip disabled
本站由 瀛睿律師事務所 擔任常年法律顧問 | 免責聲明 | 本網站已依台灣網站內容分級規定處理 | 連絡我們 | 訪客留言