onkey 加法运算
来源:互联网 发布:淘宝一千零一夜哪里看 编辑:程序博客网 时间:2024/05/08 22:15
Addition:实现加法运算
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!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 runat="server">
<title>AJAX加法运算示例</title>
<script type ="text/javascript" >
var xmlHttp;
function createXMLHttpRequest()
{
if(window.XMLhttpRequest)
{
xmlHttp= new XMLHttpRequest();//mozilla浏览器
}
else if(window.ActiveXObject)
{
try
{
xmlHttp=new ActiveXObject("Msxm12.XMLHTTP");//IE旧版本
}
catch(e)
{}
try
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");//IE新版本
}
catch(e)
{
}
if(!xmlHttp)
{
window.alert("不能创建XMLHttpRequest对象实例");
return false;
}
}
}
function addNumber()
{
createXMLHttpRequest();
var url="Handler.ashx?Num1="+document.getElementById("TxtNum1").value+"&Num2="+document.getElementById("TxtNum2").value;
;
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange=showResult;
xmlHttp.send(null);
}
function showResult()
{
if(xmlHttp.readyState==4)
{
if(xmlHttp.status==200)//这里出错一次
{
document.getElementById("TxtResult").value=xmlHttp.responseText;
}
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div style="text-align: center">
<input id="TxtNum1" type="text" value="0" onkeyup="addNumber()" />+<input id="TxtNum2" type="text" value="0" onkeyup ="addNumber()" />=
<input id="TxtResult" type="text" /></div>
</form>
</body>
</html>
Handler.ashx
<%@ WebHandler Language="C#" Class="Handler" %>
using System;
using System.Web;
public class Handler : IHttpHandler {
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain";
int result = Convert.ToInt32(context.Request.QueryString["Num1"]) + Convert.ToInt32(context.Request.QueryString["Num2"]);
context.Response.Write(result);//返回值
}
public bool IsReusable {
get {
return false;
}
}
}
- onkey 加法运算
- 加法运算
- 加法运算
- 虚数的加法运算
- 第二课 加法运算
- 位运算实现加法
- 大非负整数加法运算
- 高精度计算----加法运算
- js float加法运算
- 位运算实现加法
- 位运算实现加法
- 不用 + -× /实现加法运算
- PowerShell中的加法运算
- 整数的加法运算
- jQuery的加法运算
- 位运算 实现加法
- 位运算实现加法
- 高精度运算 大数加法
- C#调用非托管DLL的APIs
- 两种不同的存储过程调用方法
- 生意就是这样做成的
- .net代码生成器大全
- 生成字符SQL语句基本规则
- onkey 加法运算
- 执行带参数的存储过程的方法II(相对通用)
- 46个不可不知的生活小常识
- 逻辑地址、线性地址、物理地址
- 如何在GridView的RowCommand事件中获取当前的GridViewRow
- javascript读写Cookie函数
- Tomcat中用web.xml控制Web应
- Ajax基础(XMLHttpRequest对象)回顾
- OCX读取客户端信息