查看完整版本: 計算機(2)

danny 2007-12-7 10:24

計算機(2)

[code]<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>

<!------- JS計算機開始-------->
<form name="Keypad" action>
 <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">
     <a href=http://www.moninet.com.tw/ target=_blank>摩尼網</a> 
    </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> 
<!------- JS計算機結束-------->[/code]
頁: [1]
查看完整版本: 計算機(2)