用JS写个计算器,要有=-*/,还有10进制换其他的进制

如题,快,在线=

<html>
<head>
<title></title>
<SCRIPT LANGUAGE="javascript">
</SCRIPT>
</head>
<body>
<FORM name=Keypad action="">
<CENTER>提示:先输入要转换的数,点击相关按钮进行转换。<BR>HEX:将十进制转十六进制 <BR>OCT:将十进制转八进制<BR>BIN:将十进制转二进制 </CENTER>
<DIV align=center>
<TABLE height=60 cellSpacing=0 cellPadding=0 width=249 align=center bgColor=#d4d0c8 border=1>
<TBODY>
<TR>
<TD align=middle colSpan=4>
<P align=center><INPUT class=text_input size=30 value=0 name=ReadOut width="100%"> </P></TD>
<TD width=0></TD>
<TD width=50><INPUT class=Button onclick=Clear() type=button value=" C " name=btnClear> </TD>
<TD><INPUT class=Button onclick=ClearEntry() type=button value=" CE " name=btnClearEntry2> </TD></TR>
<TR>
<TD width=50><INPUT class=Button onclick=NumPressed(7) type=button value=" 7 " name=btnSeven> </TD>
<TD width=50><INPUT class=Button onclick=NumPressed(8) type=button value=" 8 " name=btnEight> </TD>
<TD width=50><INPUT class=Button onclick=NumPressed(9) type=button value=" 9 " name=btnNine> </TD>
<TD width=50><INPUT class=Button onclick=hexchange() type=button value=HEX name=btnHex> </TD>
<TD width=0></TD>
<TD width=50><INPUT class=Button onclick=Neg() type=button value=" +/- " name=btnNeg> </TD>
<TD><INPUT class=Button onclick=Percent() type=button value=" % " name=btnPercent> </TD></TR>
<TR>
<TD width=50><INPUT class=Button onclick=NumPressed(4) type=button value=" 4 " name=btnFour> </TD>
<TD width=50><INPUT class=Button onclick=NumPressed(5) type=button value=" 5 " name=btnFive> </TD>
<TD width=50><INPUT class=Button onclick=NumPressed(6) type=button value=" 6 " name=btnSix> </TD>
<TD width=50><INPUT class=Button onclick=octchange() type=button value=OCT name=btnClearEntry222> </TD>
<TD width=0></TD>
<TD align=middle width=50><INPUT class=Button onclick="Operation('+')" type=button value=" + " name=btnPlus> </TD>
<TD align=middle><INPUT class=Button onclick="Operation('-')" type=button value=" - " name=btnMinus> </TD></TR>
<TR>
<TD width=50><INPUT class=Button onclick=NumPressed(1) type=button value=" 1 " name=btnOne> </TD>
<TD width=50><INPUT class=Button onclick=NumPressed(2) type=button value=" 2 " name=btnTwo> </TD>
<TD width=50><INPUT class=Button onclick=NumPressed(3) type=button value=" 3 " name=btnThree> </TD>
<TD width=50><INPUT class=Button onclick=binchange() type=button value=BIN name=btnClearEntry223> </TD>
<TD width=0></TD>
<TD align=middle width=50><INPUT class=Button onclick="Operation('*')" type=button value=" * " name=btnMultiply> </TD>
<TD align=middle><INPUT class=Button onclick="Operation('/')" type=button value=" / " name=btnDivide> </TD></TR>
<TR>
<TD width=50><INPUT class=Button onclick=NumPressed(0) type=button value=" 0 " name=btnZero> </TD>
<TD width=50><INPUT class=Button onclick=Decimal() type=button value=" . " name=btnDecimal> </TD>
<TD colSpan=5><INPUT class=Button onclick="Operation('=')" type=button value=" = " name=btnEquals> </TD></TR></TBODY></TABLE></DIV></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>

</body>
</html>
温馨提示:内容为网友见解,仅供参考
第1个回答  2007-01-15
一款用js编写的通用科学计算器
新建文本文档,把下面代码粘贴过去,然后把TXT改成html就OK了

代码太长了,给你地址,你自己复制吧.
http://bbs.blueidea.com/archiver/tid-2510043.html

测试过了,可以用

可以转换进制
第2个回答  2007-01-15
<html>
<head>
<title></title>
<SCRIPT LANGUAGE="javascript">
</SCRIPT>
</head>
<body>
<FORM name=Keypad action="">
<CENTER>提示:先输入要转换的数,点击相关按钮进行转换。<BR>HEX:将十进制转十六进制 <BR>OCT:将十进制转八进制<BR>BIN:将十进制转二进制 </CENTER>
<DIV align=center>
<TABLE height=60 cellSpacing=0 cellPadding=0 width=249 align=center bgColor=#d4d0c8 border=1>
<TBODY>
<TR>
<TD align=middle colSpan=4>
<P align=center><INPUT class=text_input size=30 value=0 name=ReadOut width="100%"> </P></TD>
<TD width=0></TD>
<TD width=50><INPUT class=Button onclick=Clear() type=button value=" C " name=btnClear> </TD>
<TD><INPUT class=Button onclick=ClearEntry() type=button value=" CE " name=btnClearEntry2> </TD></TR>
<TR>
<TD width=50><INPUT class=Button onclick=NumPressed(7) type=button value=" 7 " name=btnSeven> </TD>
<TD width=50><INPUT class=Button onclick=NumPressed(8) type=button value=" 8 " name=btnEight> </TD>
<TD width=50><INPUT class=Button onclick=NumPressed(9) type=button value=" 9 " name=btnNine> </TD>
<TD width=50><INPUT class=Button onclick=hexchange() type=button value=HEX name=btnHex> </TD>
<TD width=0></TD>
<TD width=50><INPUT class=Button onclick=Neg() type=button value=" +/- " name=btnNeg> </TD>
<TD><INPUT class=Button onclick=Percent() type=button value=" % " name=btnPercent> </TD></TR>
<TR>
<TD width=50><INPUT class=Button onclick=NumPressed(4) type=button value=" 4 " name=btnFour> </TD>
<TD width=50><INPUT class=Button onclick=NumPressed(5) type=button value=" 5 " name=btnFive> </TD>
<TD width=50><INPUT class=Button onclick=NumPressed(6) type=button value=" 6 " name=btnSix> </TD>
<TD width=50><INPUT class=Button onclick=octchange() type=button value=OCT name=btnClearEntry222> </TD>
<TD width=0></TD>
<TD align=middle width=50><INPUT class=Button onclick="Operation('+')" type=button value=" + " name=btnPlus> </TD>
<TD align=middle><INPUT class=Button onclick="Operation('-')" type=button value=" - " name=btnMinus> </TD></TR>
<TR>
<TD width=50><INPUT class=Button onclick=NumPressed(1) type=button value=" 1 " name=btnOne> </TD>
<TD width=50><INPUT class=Button onclick=NumPressed(2) type=button value=" 2 " name=btnTwo> </TD>
<TD width=50><INPUT class=Button onclick=NumPressed(3) type=button value=" 3 " name=btnThree> </TD>
<TD width=50><INPUT class=Button onclick=binchange() type=button value=BIN name=btnClearEntry223> </TD>
<TD width=0></TD>
<TD align=middle width=50><INPUT class=Button onclick="Operation('*')" type=button value=" * " name=btnMultiply> </TD>
<TD align=middle><INPUT class=Button onclick="Operation('/')" type=button value=" / " name=btnDivide> </TD></TR>
<TR>
<TD width=50><INPUT class=Button onclick=NumPressed(0) type=button value=" 0 " name=btnZero> </TD>
<TD width=50><INPUT class=Button onclick=Decimal() type=button value=" . " name=btnDecimal> </TD>
<TD colSpan=5><INPUT class=Button onclick="Operation('=')" type=button value=" = " name=btnEquals> </TD></TR></TBODY></TABLE></DIV></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);
</SCRIPT>

</body>
</html>
就可以了

用JS写个计算器,要有=-*\/,还有10进制换其他的进制
<SCRIPT LANGUAGE="javascript"> <\/SCRIPT> <FORM name=Keypad action=""> <CENTER>提示:先输入要转换的数,点击相关按钮进行转换。<BR>HEX:将十进制转十六进制 <BR>OCT:将十进制转八进制<BR>BIN:将十进制转二进制 <\/CENTER> <DIV align=center> <TABLE height=60 cellSpacing=0 cellPadding...

用css js做一个网页版的计算器,要有加减乘除运算,和归零删除键
<!DOCTYPE html> 计数器 + - * \/ =

怎么用代码实现2进制、8进制、10进制、16进制的计算和转换?
8,10,16];var txts = document.getElementsByName("txt");var any = function (i) {txts[i].onkeyup = function () {var val = this.value;for (var j = 0;

js制作简易计算器我怎样优化这个代码,写了很多重复的了
js:\/*** 操作两个值* 传入两个值,得到相应运算符的值*\/function OperatorTwoNum(num1,num2,operator){num1 = parseFloat(num1);num2 = parseFloat(num2);switch(operator){case "+":return num1 + num2;case "-":return num1 - num2;case "*":return num1 * num2;case "\/":ret...

...的js 代码 写的计算器 有加减乘除等号 还有mc mr ms m+m-就行了...
11求一个简单 的js 代码 写的计算器 有加减乘除等号 还有mc mr ms m+m-就行了 要求每一段代码带上注释重复的肯定不用注释了采纳会追加贰佰分绝不食言... 要求每一段代码带上注释 重复的肯定不用注释了 采纳会追加贰佰分 绝不食言 展开  我来答 ...

仿照计算器实现连加连减测试是否是运算,用vue.js来写?
Vue.js Calculator Calculate Result: {{ result }} new Vue({ el: '#app',data: { expression: '',result: null },methods: { calculate() { \/\/ 判断是否是运算 if (\/^[0-9+\\-*\/. ]+$\/.test(this.expression)) { this.result = eval(this.expression);} else { this...

js文本框 计算器
我随便写了写。写的有点粗,自己调下。加些css.还有计算公司那里我做了最简单的计算。你当然那要写过下 试过。你点下1+2能等于3的 test1: test2: function createOjb(obj,er){ if(document.getElementById(obj.id+"div")!=null){ return;} var div = document.createElement("div");...

js制作一个简易计算器?
用javascript编写计算器对于JavaScript来说,编写一个简单的计算器的核心,是借用js提供的eval函数,eval函数可以对给定的字符串表达式执行运算,并返回结果。举例来说:s=eval(50+20-30*40\/20);其结果是10。vars=3+4*5-4alert(eval((+s+)));用eval就可以了。放到最上面时,下面的文本框并不...

一个js计算器代码里的四舍五入问题
alert(10\/3);alert(parseInt(10\/3,10));alert((10\/3).toFixed(2));

如何用css js制作计算器?
js加减乘除计算器代码 body,ul{ margin:0px; padding:0px;} body{ background:#AF6332} li{ list-style:none;} .fl{ float:left;} .fr{ float:right;} .clearfix:after{ content:""; display:block;clear:both} .clearfix{zoom:1;} \/*是用inset可以将外部阴影改成内部阴影;若要实现...

相似回答