简易计算器的代码,js简易计算器代码

1,js简易计算器代码1. html是从上往下逐行执行的,当执行到“var resultValue=http://www.lisdn.com/mnsj/hhjy/document.getElementById("result").value;”时id为result的页面元素还没有创建,所以出错 。应该把这句放在getNum函数里面2. getNum函数应该这样写function getNum(num)var result = document.getElementById("result");result.value += num;}3. 双引号里面应为单引号onclick="getNum(9)"
2,急需一个简易计算器代码谢谢using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace 1111class Programstatic void Main(string[] args)string a;double b;int c, d,e;Console.WriteLine("输入一个算术的运算式子:例如+、-、*、/、^");a = Console.ReadLine();Console.WriteLine("第一个数:");d = int.Parse(Console.ReadLine());Console.WriteLine("第二个数:");e = int.Parse(Console.ReadLine());switch (a)case "+":c = d + e;Console.WriteLine(d.ToString()+"+"+e.ToString()+"="+c);break;case "-":c = d - e;Console.WriteLine(d.ToString() + "-" + e.ToString() + "=" + c);break;case "*":c = d * e;Console.WriteLine(d.ToString() + "*" + e.ToString() + "=" + c);break;case "/":c = d / e;Console.WriteLine(d.ToString() + "/" + e.ToString() + "=" + c);break;case "^":b = Math.Pow(d,e);Console.WriteLine(d.ToString() + "^" + e.ToString() + "=" + b);break;}Console.ReadLine();}}}c#的用手机赛百度(计算器)【简易计算器的代码,js简易计算器代码】
3 , 简单的jsp计算器代码SimpleBean.javapackage com.JSP_P11.ch5;public class SimpleBean...String first;String second;String operator;double result;public void setFirst(String first)...this.first=first;}public void setSecond(String second)...this.second=second;}public void setOperator(String operator)...this.operator=operator;}public String getFirst()...return this.first;}public String getSecond()...return this.second;}public String getOperator()...return this.operator;}public double getResult()...return this.result;}public void calculate()...double one=Double.parseDouble(first);//类型转换也感觉没有C#直观double two=Double.parseDouble(second);try//C#中switch可以处理字符,而java不行了,有点不爽:(...if(operator.equals("+")) result=one+two;else if(operator.equals("-")) result=one-two;else if(operator.equals("*")) result=one*two;else if(operator.equals("/")) result=one/two;}catch(Exception e)...System.out.print(e);}}}index.jsp<%@ page language="java" import="java.applet.*" pageEncoding="GB2312"%><%@page import="com.JSP_P11.ch5.SimpleBean;"%><jsp:useBean id="calculator" scope="request" class="com.JSP_P11.ch5.SimpleBean"><jsp:setProperty name="calculator" property="*"/></jsp:useBean><html><head><title>计算器</title></head><body><%try...calculator.calculate();out.print(calculator.getFirst()+calculator.getOperator()+calculator.getSecond()+"="+calculator.getResult());}catch(Exception e)...System.out.print(e);}%><hr><form name="form1" action="index.jsp"><table width="75" border="1" bordercolor="#003300"><tr bgcolor="#999999"><td colspan="2">simple calculator</td></tr><tr><td>第一个操作数</td><td><input type=text name="first"></td></tr><tr><td>操作符</td><td><select name="operator"><option value="http://www.lisdn.com/mnsj/hhjy/+">+</option><option value="http://www.lisdn.com/mnsj/hhjy/-">-</option><option value="http://www.lisdn.com/mnsj/hhjy/*">*</option><option value="http://www.lisdn.com/">/</option></select></td></tr><tr><td>第二个操作数</td><td><input type=text name="second"></td></tr><tr><td colspan="2" bgcolor="#cccccc"><input type=submit value="http://www.lisdn.com/mnsj/hhjy/计算"></td></tr></table></form></body></html>麻烦
4 , 简易计算器代码以前做了一个,不知道合不合阁下的意思......代码如下:<html><head><title>低b计算器</title><script language="javascript" type="text/javascript">var a;function t()var num1=parsefloat(document.form1.textfield.value);var num2=parsefloat(document.form1.textfield2.value);var result;switch(a)case "1":result=num1+num2;document.form1.textfield3.value=http://www.lisdn.com/mnsj/hhjy/result;a="0";break;case "2":result=num1-num2;document.form1.textfield3.value=http://www.lisdn.com/mnsj/hhjy/result;a="0";break;case "3":result=num1*num2;document.form1.textfield3.value=http://www.lisdn.com/mnsj/hhjy/result;a="0";break;case "4":result=num1/num2;document.form1.textfield3.value=http://www.lisdn.com/mnsj/hhjy/result;a="0";break;default:document.form1.textfield3.value=http://www.lisdn.com/mnsj/hhjy/("请问您要执行哪种运算?");break;}}function plus()a="1";}function subtract()a="2";}function multiply()a="3";}function divide()a="4";}</script></head><body><form id="form1" name="form1" method="post" action=""><label><input type="text" name="textfield" id="textfield" /><br /><input type="button" name="button" id="button" value="http://www.lisdn.com/mnsj/hhjy/+" onclick="plus()"/><input type="button" name="button2" id="button2" value="http://www.lisdn.com/mnsj/hhjy/-" onclick="subtract()"/><input type="button" name="button3" id="button3" value="http://www.lisdn.com/mnsj/hhjy/*" onclick="multiply()"/><input type="button" name="button4" id="button4" value="http://www.lisdn.com/" onclick="divide()"/><br /></label><label><input type="text" name="textfield2" id="textfield2" /><br /><input type="button" name="button5" id="button5" valuehttp://www.lisdn.com/mnsj/hhjy/="=" onclick="t()"/><br /></label><label><input type="text" name="textfield3" id="textfield3" /><br /></label></form></body></html>虽然简易 , 不过我花了一天才做好 。首先text1.text的enable属性为falseform1的maxbuttun属性为falseDim a(3) As DoubleDim c As IntegerDim b As BooleanDim d As StringDim e As BooleanPrivate Sub Command10_Click()/*命名为“零”的command*/If b ThenText1.Text = Text1.Text & "0"ElseIf Text1.Text = "0." ThenElseIf e = True ThenText1.Text = "0."e = FalseElseText1.Text = Left(Text1.Text, Len(Text1.Text) - 1) & "0" & "."End IfEnd SubPrivate Sub Command11_Click()*/命名为“点”的commond/* b = TrueEnd SubPrivate Sub Command12_Click()*/命名为“等于”的commond/* If c = 0 ThenElsea(2) = Val(Text1.Text)If c = 1 Thena(3) = a(1) + a(2)If InStr(a(3), ".") = 1 ThenText1.Text = "0" & a(3)ElseIf InStr(a(3), ".") = 0 ThenText1.Text = a(3) & "."ElseText1.Text = a(3)End IfElseIf c = 2 Thena(3) = a(1) - a(2)If InStr(a(3), ".") = 1 ThenText1.Text = "0" & a(3)ElseIf InStr(a(3), ".") = 0 ThenText1.Text = a(3) & "."ElseText1.Text = a(3)End IfElseIf c = 3 Thena(3) = a(1) * a(2)If InStr(a(3), ".") = 1 ThenText1.Text = "0" & a(3)ElseIf InStr(a(3), ".") = 0 ThenText1.Text = a(3) & "."ElseText1.Text = a(3)End IfElseIf c = 4 ThenIf a(2) = 0 Thend = MsgBox("除数为零!", "64", "错误")Elsea(3) = a(1) / a(2)If InStr(a(3), ".") = 1 ThenText1.Text = "0" & a(3)ElseIf InStr(a(3), ".") = 0 ThenText1.Text = a(3) & "."ElseText1.Text = a(3)End IfEnd IfEnd IfEnd Ifc = 0b = Falsee = TrueEnd SubPrivate Sub Command13_Click()*/命名为“加”的commond/* c = 1a(1) = Val(Text1.Text)b = Falsee = TrueEnd SubPrivate Sub Command14_Click()*/命名为“减”的commond/* c = 2a(1) = Val(Text1.Text)b = Falsee = TrueEnd SubPrivate Sub Command15_Click()*/命名为“乘”的commond/* c = 3a(1) = Val(Text1.Text)b = Falsee = TrueEnd SubPrivate Sub Command16_Click()*/命名为“除”的commond/* c = 4a(1) = Val(Text1.Text)b = Falsee = TrueEnd SubPrivate Sub Command17_Click()*/命名为“清空”commond/* c = 0b = Falsee = FalseText1.Text = "0."End SubPrivate Sub Command2_Click()*/命名为“二”的commond/* If b ThenText1.Text = Text1.Text & "2"ElseIf Text1.Text = "0." ThenText1.Text = "2."ElseIf e = True ThenText1.Text = "2."e = FalseElseText1.Text = Left(Text1.Text, Len(Text1.Text) - 1) & "2" & "."End IfEnd SubPrivate Sub Command3_Click()*/命名为“三”的commond/* If b ThenText1.Text = Text1.Text & "3"ElseIf Text1.Text = "0." ThenText1.Text = "3."ElseIf e = True ThenText1.Text = "3."e = FalseElseText1.Text = Left(Text1.Text, Len(Text1.Text) - 1) & "3" & "."End IfEnd SubPrivate Sub Command4_Click()*/命名为“四”的commond/* If b ThenText1.Text = Text1.Text & "4"ElseIf Text1.Text = "0." ThenText1.Text = "4."ElseIf e = True ThenText1.Text = "4."e = FalseElseText1.Text = Left(Text1.Text, Len(Text1.Text) - 1) & "4" & "."End IfEnd SubPrivate Sub Command6_Click()*/命名为“六“的commond/* If b ThenText1.Text = Text1.Text & "6"ElseIf Text1.Text = "0." ThenText1.Text = "6."ElseIf e = True ThenText1.Text = "6."e = FalseElseText1.Text = Left(Text1.Text, Len(Text1.Text) - 1) & "6" & "."End IfEnd SubPrivate Sub Command7_Click()*/命名为“七”的commond/* If b ThenText1.Text = Text1.Text & "7"ElseIf Text1.Text = "0." ThenText1.Text = "7."ElseIf e = True ThenText1.Text = "7."e = FalseElseText1.Text = Left(Text1.Text, Len(Text1.Text) - 1) & "7" & "."End IfEnd SubPrivate Sub Command8_Click()*/命名为“八”的commond/* If b ThenText1.Text = Text1.Text & "8"ElseIf Text1.Text = "0." ThenText1.Text = "8."ElseIf e = True ThenText1.Text = "8."e = FalseElseText1.Text = Left(Text1.Text, Len(Text1.Text) - 1) & "8" & "."End IfEnd SubPrivate Sub Command9_Click()*/命名为“九”的commond/* If b ThenText1.Text = Text1.Text & "9"ElseIf Text1.Text = "0." ThenText1.Text = "9."ElseIf e = True ThenText1.Text = "9."e = FalseElseText1.Text = Left(Text1.Text, Len(Text1.Text) - 1) & "9" & "."End IfEnd SubPrivate Sub Command1_Click()*/命名为“一”的commond/* If b ThenText1.Text = Text1.Text & "1"ElseIf Text1.Text = "0." ThenText1.Text = "1."ElseIf e = True ThenText1.Text = "1."e = FalseElseText1.Text = Left(Text1.Text, Len(Text1.Text) - 1) & "1" & "."End IfEnd SubPrivate Sub Command5_Click()*/命名为“五”的commond/* If b ThenText1.Text = Text1.Text & "5"ElseIf Text1.Text = "0." ThenText1.Text = "5."ElseIf e = True ThenText1.Text = "5."e = FalseElseText1.Text = Left(Text1.Text, Len(Text1.Text) - 1) & "5" & "."End IfEnd SubPrivate Sub Form_Load()c = 0b = Falsee = FalseText1.Text = "0."End Sub

    推荐阅读