導航:首頁 > 編程語言 > js鍵盤實現鍵盤輸入計算器

js鍵盤實現鍵盤輸入計算器

發布時間:2024-07-18 14:41:34

1. 用js代碼做一個簡易計算器

functiontest(){
vartxt1=document.getElementById("txt1"),
txt2=document.getElementById("txt2"),
txt3=document.getElementById("txt3"),
opt=document.getElementById("sel");
txt3.value=eval(txt1.value+opt.value+txt2.value);//eval函數可計算某個字元串,並執行其中的的js代碼
}
<inputtype="text"id="txt1"/>
<selectid="sel">
<optionvalue="+">+</option>
<optionvalue="-">-</option>
<optionvalue="*">*</option>
<optionvalue="/">/</option>
</select>
<inputtype="text"id="txt2"/>
=
<inputtype="text"id="txt3"/>
<inputtype="button"id="btn"value="計算"onclick="test()"/>

2. 用javaScript做一個簡易的計算器

我剛學javaScript做一計算器,請看看!多多交流!~~``

<html>
<head>
<title>計算器</title>
</head>
<body bgcolor="#33FF99" onload="FKeyPad.ReadOut.focus();FKeyPad.ReadOut.select();">
<FORM name="Keypad" action="">
<TABLE align="center">
<B>
<TABLE align="center" border=3 width=60 height=80 cellpadding=2 cellspacing=5 borderlight="#008080">
<tr align="center">
<td bordercolor="#FF33CC" bordercolordark="#cc0066" bordercolor="#FF9966" bordercolorlight="#CC9933" colspan=10 align=center>網頁計算器</td>
</tr>
<tr align="center">
<td bordercolor="#FF33CC" bordercolordark="#cc0066" bordercolor="#FF9966" bordercolorlight="#CC9933" colspan=10 align=right><input name="ReadOut" type="Text" onkeypress="CheckOut()" size=40 value="0"
width=100%></td>
</tr>
<tr align="center">
<td bordercolordark="#cc0066" bordercolor="#FF9966" bordercolorlight="#CC9933"><input name="btnsin" type="Button" value=" sin " onclick="useFun ('sin')"></td>
<td bordercolordark="#cc0066" bordercolor="#FF9966" bordercolorlight="#CC9933"><input name="btncos" type="Button" value=" cos " onclick="useFun ('cos')"></td>
<td bordercolordark="#cc0066" bordercolor="#FF9966" bordercolorlight="#CC9933"><input name="btnOne" type="Button" value=" 1 " onclick="NumPressed(1)"></td>
<td bordercolordark="#cc0066" bordercolor="#FF9966" bordercolorlight="#CC9933"><input name="btnTwo" type="Button" value=" 2 " onclick="NumPressed(2)"></td>
<td bordercolordark="#cc0066" bordercolor="#FF9966" bordercolorlight="#CC9933"><input name="btnThree" type="Button" value=" 3 " onclick="NumPressed(3)"></td>
<td bordercolordark="#cc0066" bordercolor="#FF9966" bordercolorlight="#CC9933"><input name="btnPlus" type="Button" value=" + " onclick="Operation('+')"> </td>
</tr>
<tr align="center">
<td bordercolordark="#cc0066" bordercolor="#FF9966" bordercolorlight="#CC9933"><input name="btnasin" type="Button" value=" asin " onclick="useFun ('asin')"></td>
<td bordercolordark="#cc0066" bordercolor="#FF9966" bordercolorlight="#CC9933"><input name="btnacos" type="Button" value=" acos " onclick="useFun ('acos')"></td>
<td bordercolordark="#cc0066" bordercolor="#FF9966" bordercolorlight="#CC9933"><input name="btnFour" type="Button" value=" 4 " onclick="NumPressed(4)"></td>
<td bordercolordark="#cc0066" bordercolor="#FF9966" bordercolorlight="#CC9933"><input name="btnFive" type="Button" value=" 5 " onclick="NumPressed(5)"></td>
<td bordercolordark="#cc0066" bordercolor="#FF9966" bordercolorlight="#CC9933"><input name="btnSix" type="Button" value=" 6 " onclick="NumPressed(6)"></td>
<td bordercolordark="#cc0066" bordercolor="#FF9966" bordercolorlight="#CC9933"><input name="btnMinus" type="Button" value=" - " onclick="Operation('-')"></td>
</tr>
<tr align="center">
<td bordercolordark="#cc0066" bordercolor="#FF9966" bordercolorlight="#CC9933"><input name="btntan" type="Button" value=" tan " onclick="useFun ('tan')"></td>
<td bordercolordark="#cc0066" bordercolor="#FF9966" bordercolorlight="#CC9933"><input name="btnatan" type="Button" value=" atan " onclick="useFun ('atan')"></td>
<td bordercolordark="#cc0066" bordercolor="#FF9966" bordercolorlight="#CC9933"><input name="btnSeven" type="Button" value=" 7 " onclick="NumPressed(7)"></td>
<td bordercolordark="#cc0066" bordercolor="#FF9966" bordercolorlight="#CC9933"><input name="btnEight" type="Button" value=" 8 " onclick="NumPressed(8)"></td>
<td bordercolordark="#cc0066" bordercolor="#FF9966" bordercolorlight="#CC9933"><input name="btnNine" type="Button" value=" 9 " onclick="NumPressed(9)"></td>
<td bordercolordark="#cc0066" bordercolor="#FF9966" bordercolorlight="#CC9933"><input name="btnMultiply" type="Button" value=" * " onclick="Operation('*')"></td>
</tr>
<tr align="center">
<td bordercolordark="#cc0066" bordercolor="#FF9966" bordercolorlight="#CC9933"><input name="btnlog" type="Button" value=" log " onclick="useFun ('log')"></td>
<td bordercolordark="#cc0066" bordercolor="#FF9966" bordercolorlight="#CC9933"><input name="btnexp" type="Button" value=" exp " onclick="useFun ('exp')"></td>
<td bordercolordark="#cc0066" bordercolor="#FF9966" bordercolorlight="#CC9933"><input name="btnZero" type="Button" value=" 0 " onclick="NumPressed(0)"></td>
<td bordercolordark="#cc0066" bordercolor="#FF9966" bordercolorlight="#CC9933"><input name="btnDecimal" type="Button" value=" . " onclick="Decimal()"></td>
<td bordercolordark="#cc0066" bordercolor="#FF9966" bordercolorlight="#CC9933"><input name="btnNeg" type="Button" value=" +/- " onclick="Neg()"></td>
<td bordercolordark="#cc0066" bordercolor="#FF9966" bordercolorlight="#CC9933"><input name="btnDivide" type="Button" value=" / " onclick="Operation('/')"></td>
</tr>
<tr align="center">
<td bordercolordark="#cc0066" bordercolor="#FF9966" bordercolorlight="#CC9933"><input name="btnsqrt" type="Button" value=" sqrt " onclick="useFun ('sqrt')"></td>
<td bordercolordark="#cc0066" bordercolor="#FF9966" bordercolorlight="#CC9933"><input name="btnOx" type="Button" value=" 1/x " onclick="useFun ('1/x')"></td>
<td bordercolordark="#cc0066" bordercolor="#FF9966" bordercolorlight="#CC9933"><input name="btnXt" type="Button" value=" x^2 " onclick="useFun ('x^2')"></td>
<td bordercolordark="#cc0066" bordercolor="#FF9966" bordercolorlight="#CC9933"><input name="btnXthr" type="Button" value=" x^3 " onclick="useFun ('x^3')"></td>
<td bordercolordark="#cc0066" bordercolor="#FF9966" bordercolorlight="#CC9933"><input name="btnpi" type="Button" value=" pi " onclick=FKeyPad.ReadOut.value=Math.PI></td>
<td bordercolordark="#cc0066" bordercolor="#FF9966" bordercolorlight="#CC9933"><input name="btnEquals" type="Button" value=" = " onclick="Operation('=')"></td>
</tr>
<tr align="center">
<td bordercolordark="#cc0066" bordercolor="#FF9966" bordercolorlight="#CC9933"><input name="btnDivide" type="Button" value=" N! " onclick="ni ()"></td>
<td bordercolordark="#cc0066" bordercolor="#FF9966" bordercolorlight="#CC9933"><input name="btnDivide" type="Button" value=" pow " onclick="Operation('pow')"></td>
<td bordercolordark="#cc0066" bordercolor="#FF9966" bordercolorlight="#CC9933"><input name="btnDivide" type="Button" value=" E " onclick=FKeyPad.ReadOut.value=Math.E></td>
<td bordercolordark="#cc0066" bordercolor="#FF9966" bordercolorlight="#CC9933"><input name="btnClear" type="Button" value=" C " onclick="Clear()"></td>
<td bordercolordark="#cc0066" bordercolor="#FF9966" bordercolorlight="#CC9933"><input name="btnClearEntry" type="Button" value=" CE " onclick="ClearEntry()"></td>
<td bordercolordark="#cc0066" bordercolor="#FF9966" bordercolorlight="#CC9933"><input name="btnReturn" type="Button" value="返 回" onclick="goReturn()"></td>
</tr>
<tr align="center">
<td bordercolordark="#cc0066" bordercolor="#FF9966" bordercolorlight="#CC9933"><input name="btnmod" type="Button" value=" MOD " onclick="Operation('MOD')"></td>
<td bordercolordark="#cc0066" bordercolor="#FF9966" bordercolorlight="#CC9933"><input name="btnDivide" type="Button" value=" INT" onclick=FKeyPad.ReadOut.value=parseInt(FKeyPad.ReadOut.value,10)></td>
<td bordercolordark="#cc0066" bordercolor="#FF9966" bordercolorlight="#CC9933"><input name="btnmod" type="Button" value=" HEX " onclick="hexchange ()"></td>
<td bordercolordark="#cc0066" bordercolor="#FF9966" bordercolorlight="#CC9933"><input name="btnmod" type="Button" value=" OCT " onclick="octchange ()"></td>
<td bordercolordark="#cc0066" bordercolor="#FF9966" bordercolorlight="#CC9933"><input name="btnmod" type="Button" value=" BIN " onclick="binchange ()"></td>
</tr>
</TABLE>
</TABLE>
</B>
</FORM>
</CENTER>
<font face="Verdana, Arial, Helvetica" size=2>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var FKeyPad = document.forms['Keypad'];
var Accum = "0";
var FlagNewNum = false;
var PendingOp = "";
function longCount(str1,str2,type)
{
var comma1 = 0;
if (str1.indexOf(".")!=-1)
{
str1 = str1.replace(/0*$/,"");
comma1 = str1.length - str1.indexOf(".")-1;
}
var comma2 = 0;
if (str2.indexOf(".")!=-1)
{
str2 = str2.replace(/0*$/,"");
comma2 = str2.length - str2.indexOf(".")-1;
}
str1 = str1.replace(/\./,"");
str2 = str2.replace(/\./,"");
var value,comma;
if (type!="*")
{
if (comma1>comma2)
{
for (var i=0;i<comma1-comma2;i++) str2 += "0";
comma = (type=="/")?0:comma1;
}else
{
for (var i=0;i<comma2-comma1;i++) str1 += "0";
comma = (type=="/")?0:comma2;
}
}else
{
comma = comma1 + comma2;
}
if (type=="+")
{
value = parseInt(str1,10) + parseInt(str2,10);
}else if (type=="-")
{
value = parseInt(str1,10) - parseInt(str2,10);
}else if (type=="*")
{
value = parseInt(str1,10) * parseInt(str2,10);
}else if (type=="/")
{
value = parseInt(str1,10) / parseInt(str2,10);
}
else if (type=="MOD")
value = parseInt(str1,10) % parseInt(str2,10);
else if (type=="pow")
{
var a,b,s=1;
a=parseInt(str1,10);
b=parseInt(str2,10);
for(var i=1;i<=b;i++)
s=s*a;
value=parseInt(s,10);
}
value = String(value);
if (comma>0) value = value.substring(0,value.length-comma)+"."+value.substring(value.length- comma,value.length);
if (value.indexOf(".")!=-1)
value = value.replace(/0*$/,"");
return value;
}
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 || '-' == PendingOp || '/' == PendingOp || '*' == PendingOp||'MOD'==PendingOp||'pow'==PendingOp)
Accum = longCount(Accum,Readout,PendingOp);
else
Accum = Readout;
FKeyPad.ReadOut.value = Accum;
PendingOp = Op;
FKeyPad.ReadOut.focus();
FKeyPad.ReadOut.select();
}
}
function useFun (st)
{
switch(st)
{
case "sin":
FKeyPad.ReadOut.value=Math.sin(FKeyPad.ReadOut.value);
FlagNewNum=true;
break;
case "cos":
FKeyPad.ReadOut.value=Math.cos(FKeyPad.ReadOut.value);
FlagNewNum=true;
break;
case "asin":
FKeyPad.ReadOut.value=Math.asin(FKeyPad.ReadOut.value);
FlagNewNum=true;
break;
case "acos":
FKeyPad.ReadOut.value=Math.acos(FKeyPad.ReadOut.value);
FlagNewNum=true;
break;
case "tan":
FKeyPad.ReadOut.value=Math.tan(FKeyPad.ReadOut.value);
FlagNewNum=true;
break;
case "atan":
FKeyPad.ReadOut.value=Math.atan(FKeyPad.ReadOut.value);
FlagNewNum=true;
break;
case "log":
FKeyPad.ReadOut.value=Math.log(FKeyPad.ReadOut.value);
FlagNewNum=true;
break;
case "exp":
FKeyPad.ReadOut.value=Math.exp(FKeyPad.ReadOut.value);
FlagNewNum=true;
break;
case "sqrt":
FKeyPad.ReadOut.value=Math.sqrt(FKeyPad.ReadOut.value);
FlagNewNum=true;
break;
case "1/x":
FKeyPad.ReadOut.value=1/FKeyPad.ReadOut.value;
FlagNewNum=true;
break;
case "x^2":
FKeyPad.ReadOut.value=parseFloat(FKeyPad.ReadOut.value)*parseFloat(FKeyPad.ReadOut.value);
FlagNewNum=true;
break;
case "x^3":
FKeyPad.ReadOut.value=parseFloat(FKeyPad.ReadOut.value)*parseFloat(FKeyPad.ReadOut.value)*parseFloat(FKeyPad.ReadOut.value);
FlagNewNum=true;
break;

}

}
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);
}
function ni ()
{var y,k=1;
y=parseFloat(FKeyPad.ReadOut.value);
for(var x=1;x<=y;x++)
k=k*x;
FKeyPad.ReadOut.value=k;
}
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 ()
{
window.alert(FKeyPad.ReadOut.value);
FKeyPad.ReadOut.value = longCount(FKeyPad.ReadOut.value,"-1","*");
}

function goReturn()
{
top.returnValue = FKeyPad.ReadOut.value;
self.close();
}
function CheckOut()
{
var keyCode = window.event.keyCode;
if (keyCode>=48 && keyCode<=57)
{
if (FlagNewNum)
{
FKeyPad.ReadOut.value = "";
FlagNewNum = false;
}
return true;
}else if (keyCode==43 || keyCode==45 || keyCode==42 || keyCode==47 || keyCode==61) {
Operation(String.fromCharCode(keyCode));
}else if (keyCode==46) {
if (FKeyPad.ReadOut.value.indexOf(".") == -1)
return true;
}else if (keyCode==27) goReturn();
window.event.returnValue = false;
return false;
}
// End -->
</SCRIPT>
</body>
</html>

3. 加法計算器:編程由鍵盤輸入兩個整數a和b,計算出它們的和並輸出到屏幕

方法一:

#include<stdio.h>

int main()

{

int a,b,c;

c=a+b;

scanf("%d %d",&a,&b);

printf("a+b=%d", c);

return 0;

}

方法二:

var a,b:longint;begin readln(a,b); writeln(a+b);end.

c#編寫加法計算器

static void Main(string[] args)

{

bool flag = true;

Console.WriteLine("請輸入第一個加數:");

float num = 0;

float sum = 0;

if (float.TryParse(Console.ReadLine(), out num))

flag = false;

Console.WriteLine("錯誤,輸入的不是數字!程序結束。");

Console.WriteLine("請輸入第二個加數:");

if (float.TryParse(Console.ReadLine(), out num))

flag = false;

Console.WriteLine("錯誤,輸入的不是數字!程序結束。");

Console.Read();

if (flag)

{

Console.WriteLine("兩數的和是:{0}", sum.ToString());

Console.Read();

}

整除特徵

1、若一個數的末位是單偶數,則這個數能被2整除。

2、若一個數的所有數位上的數字和能被3整除,則這個整數能被3整除。

3、若一個數的末尾兩位數能被4整除,則這個數能被4整除。

4、若一個數的末位是0或5,則這個數能被5整除。

5、若一個數能被2和3整除,則這個數能被6整除。

以上內容參考:網路-整數

4. 如何使用JS編寫一個簡單的計算器

js部分
var num=0,result=0,numshow="0";
var operate=0; //判斷輸入狀態的標志
var calcul=0; //判斷計算狀態的標志
var quit=0; //防止重復按鍵的標志
function command(num){
var str=String(document.calculator.numScreen.value); //獲得當前顯示數據
str=(str!="0") ? ((operate==0) ? str : "") : ""; //如果當前值不是"0",且狀態為0,則返回當前值,否則返回空值;
str=str + String(num); //給當前值追加字元
document.calculator.numScreen.value=str; //刷新顯示
operate=0; //重置輸入狀態
quit=0; //重置防止重復按鍵的標志
}
function dzero(){
var str=String(document.calculator.numScreen.value);
str=(str!="0") ? ((operate==0) ? str + "00" : "0") : "0"; //如果當前值不是"0",且狀態為0,則返回當str+"00",否則返回"0";
document.calculator.numScreen.value=str;
operate=0;
}
function dot(){
var str=String(document.calculator.numScreen.value);
str=(str!="0") ? ((operate==0) ? str : "0") : "0"; //如果當前值不是"0",且狀態為0,則返回當前值,否則返回"0";
for(i=0; i<=str.length;i++){ //判斷是否已經有一個點號
if(str.substr(i,1)==".") return false; //如果有則不再插入
}
str=str + ".";
document.calculator.numScreen.value=str;
operate=0;
}
function del(){ //退格
var str=String(document.calculator.numScreen.value);
str=(str!="0") ? str : "";
str=str.substr(0,str.length-1);
str=(str!="") ? str : "0";
document.calculator.numScreen.value=str;
}
function clearscreen(){ //清除數據
num=0;
result=0;
numshow="0";
document.calculator.numScreen.value="0";
}
function plus(){ //加法
calculate(); //調用計算函數
operate=1; //更改輸入狀態
calcul=1; //更改計算狀態為加
}
function minus(){ //減法
calculate();
operate=1;
calcul=2;
}
function times(){ //乘法
calculate();
operate=1;
calcul=3;
}
function divide(){ //除法
calculate();
operate=1;
calcul=4;
}
function persent(){ //求余
calculate();
operate=1;
calcul=5;
}
function equal(){
calculate(); //等於
operate=1;
num=0;
result=0;
numshow="0";
}
//
function calculate(){
numshow=Number(document.calculator.numScreen.value);
if(num!=0 && quit!=1){ //判斷前一個運算數是否為零以及防重復按鍵的狀態
switch(calcul){ //判斷要輸入狀態
case 1:result=num+numshow;break; //計算"+"
case 2:result=num-numshow;break; //計算"-"
case 3:result=num*numshow;break;
case 4:if(numshow!=0){result=num/numshow;}else{document.getElementById("note").innerHTML="被除數不能為零!"; setTimeout(clearnote,4000)} break;
case 5:result=num%numshow;break;
}
quit=1; //避免重復按鍵
}
else{
result=numshow;
}
numshow=String(result);
document.calculator.numScreen.value=numshow;
num=result; //存儲當前值
}
function clearnote(){ //清空提示
document.getElementById("note").innerHTML="";
}

html部分:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>寫給新手:js表單操作(四) 簡單計算器(二)</title>
<style type="text/css">
body {
font-size:12px;
font-family:Arial, Georgia, "Times New Roman", Times, serif;
color:#555;
text-align:center;
background-color:#e2e2e2;
}
h6{
margin:0;
font-size:12px;
}
#calculator {
width:240px;
height:auto;
overflow:hidden;
margin:10px auto;
border:#fff 1px solid;
padding-bottom:10px;
background-color:#f2f2f2;
}
#calculator div {
clear:both;
}
#calculator ul{
padding:0;
margin:5px 14px;
border:#fff 1px solid;
height:auto;
overflow:hidden
}
#calculator li{
list-style:none;
float:left;
width:32px;
height:32px;
margin:5px;
display:inline;
line-height:32px;
font-size:14px;
background-color:#eaeaea;
}
#calculator li.tool{
background-color:#e2e2e2;
}
#calculator li:hover{
background-color:#f9f9f9;
cursor:pointer;
}
#calculator li:active{
background-color:#fc0;
cursor:pointer;
}
#calculator li.tool:active{
background-color:#d8e8ff;
cursor:pointer;
}
#calcu-head {
text-align:left;
padding:10px 15px 5px;
}
span.imyeah {
float:right;
color:#ccc;
}
span.imyeah a{
color:#ccc;
}
.screen{
width:200px;
height:24px;
line-height:24px;
padding:4px;
border:#e6e6e6 1px solid;
border-bottom:#f2f2f2 1px solid;
border-right:#f2f2f2 1px solid;
margin:10px auto;
direction:ltr;
text-align:right;
font-size:16px;
color:#999;
}
#calcu-foot{
text-align:left;
padding:10px 15px 5px;
height:auto;
overflow:hidden;
}
span#note{
float:left;
width:210px;
height:auto;
overflow:hidden;
color:red;
}
span.welcome{
clear:both;
color:#999;
}
span.welcome a{
float:right;
color:#999;
}
</style>
<script language="javascript">
//此處插入上面的js代碼
</script>
</head>
<body>
<div id="calculator">
<div id="calcu-head"><span class="imyeah">© <a href="http://www.cnblogs.com/imyeah/" target="_blank">I'm Yeah!</a></span><h6>簡單的計算器</h6></div>
<form name="calculator" action="" method="get">
<div id="calcu-screen">
<!--配置顯示窗口,使用onfocus="this.blur();"避免鍵盤輸入-->
<input type="text" name="numScreen" class="screen" value="0" onfocus="this.blur();" />
</div>
<div id="calcu-btn">
<ul> <!--配置按鈕-->
<li onclick="command(7)">7</li>
<li onclick="command(8)">8</li>
<li onclick="command(9)">9</li>
<li class="tool" onclick="del()">←</li>
<li class="tool" onclick="clearscreen()">C</li>
<li onclick="command(4)">4</li>
<li onclick="command(5)">5</li>
<li onclick="command(6)">6</li>
<li class="tool" onclick="times()">×</li>
<li class="tool" onclick="divide()">÷</li>
<li onclick="command(1)">1</li>
<li onclick="command(2)">2</li>
<li onclick="command(3)">3</li>
<li class="tool" onclick="plus()">+</li>
<li class="tool" onclick="minus()">-</li>
<li onclick="command(0)">0</li>
<li onclick="dzero()">00</li>
<li onclick="dot()">.</li>
<li class="tool" onclick="persent()">%</li>
<li class="tool" onclick="equal()">=</li>
</ul>
</div>
<div id="calcu-foot">
<span id="note"></span>
<span class="welcome">歡迎使用javascript計算器!<a href="http://www.cnblogs.com/imyeah" target="_blank">反饋</a></span>
</div>
</form>
</div>
</body>
</html>

5. js計算器代碼怎麼寫,通過彈窗顯示

js計算器代碼,通過彈窗顯示步驟如下。
1、js計算器代碼編寫html,實現計算器頁面視圖效果。
2、js計算器代碼編寫,實現點擊輸入數字和符號輸出結果。
3、js計算器代碼創建click1函數,判斷flag的值,如果是true就定位到第一個輸入框,如果是false就定位到第二個輸入框,將點擊傳過來的值與輸入框裡面的字元串拼接到一起。
4、js計算器代碼定義result函數,定位到兩個輸入框,取出其中的值並轉成整數,定位到隱藏輸入框,取出裡面的符號,然後判斷是什麼符號,進行相應的運算,彈出運算結果。

閱讀全文

與js鍵盤實現鍵盤輸入計算器相關的資料

熱點內容
龍江網路配置什麼路由器 瀏覽:169
如何使用指標導入數據 瀏覽:866
平時用什麼app看nba 瀏覽:503
win10想以管理員身份運行bat文件 瀏覽:85
合並單元格中的其他數據如何排序 瀏覽:331
電腦窗口程序在哪 瀏覽:281
前女友把我微信刪了又加什麼意思 瀏覽:655
win10不識別無線xboxone手柄 瀏覽:403
汽車之家app怎麼看成交價 瀏覽:908
abc文件破解密碼 瀏覽:516
怎麼登錄米家app賬號 瀏覽:165
兆歐表多少轉讀數據 瀏覽:414
多媒體網路通訊 瀏覽:747
文件上的表填不了內容該怎麼辦 瀏覽:899
弟弟迷上網路小說怎麼辦 瀏覽:766
網路上有人想訪問我的地址怎麼辦 瀏覽:730
linux解壓zip亂碼 瀏覽:839
看直播數據用哪個平台最好 瀏覽:730
win10晶元驅動程序版本 瀏覽:763
如何給word添加公式編輯器 瀏覽:666

友情鏈接