广告广告
  加入我的最爱 设为首页 风格修改
首页 首尾
 手机版   订阅   地图  繁体 
您是第 2710 个阅读者
 
发表文章 发表投票 回覆文章
  可列印版   加为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.129012 second(s),query:15 Gzip disabled
本站由 瀛睿律师事务所 担任常年法律顾问 | 免责声明 | 本网站已依台湾网站内容分级规定处理 | 连络我们 | 访客留言