ASP.net
ASP.net
后台代码
protected void Button1_Click(object sender, EventArgs e) { ric.X =double .Parse( TextBox1.Text); ric.Y =double .Parse( TextBox3.Text); ric.fuhao = DropDownList1.SelectedValue; ric.result = result; ric.Add(); ric.Sub(); ric.Mul(); ric.Div(); if (TextBox4.Text == ric.result.ToString()) { Response.Write("<script>alert('回答正确')</script>"); } else { Response.Write("<script>alert('回答错误')</script>"); } } protected void DropDownList1_TextChanged(object sender, EventArgs e) { string fuhao = DropDownList1.SelectedValue; switch (fuhao) { case"+": DropDownList1.SelectedValue = "+"; break; case"-": DropDownList1.SelectedValue = "-"; break; case"*": DropDownList1.SelectedValue = "*"; break; case"/": DropDownList1.SelectedValue = "/"; break; default: break; } }
public class Richnone { public string fuhao;//计算符号 public double result; private double x;//第一个数 public double X { get { return x; } set { x = value; } } private double y;//第二个数 public double Y { get { return y; } set { y = value; } } public void Add()//加法 { if (fuhao == "+") { result = X + Y; } } public void Sub() { if (fuhao == "-") { result = X - Y; } } public void Mul() { if (fuhao == "*") { result = X * Y; } } public void Div() { if (fuhao == "/") { result = X / Y; } } }
截图