#2
vcwindow2008-04-22 18:40
|
// JScript 文件
var xmlHttp;
function creatHttp()
{
if(window.ActiveXObject)
{
xmlHttp=new ActiveXOject("Microsoft.XMLHTTP");
}
if(window.XMLHttpRequest)
{
xmlHttp=new XMLHttpRequest();
}
}
function checkName(name)
{
creatHttp();
var url="check.aspx?Name="+name;
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange=backName;
xmlHttp.send(null);
}
function backName()
{
if(xmlHttp.readyState==4)
{
if(xmlHttp.status==200)
{
if(xmlHttp.responseText=="true")
{document.getElementById("img1").src="image/1.jpg";}
else
{document.getElementById("img1").src="image/2.jpg";}
}
}
}
//checkName.asp文件
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class check : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string name = Request.QueryString["Name"].ToString();
if (name == "aaa")
{ Response.Write("true");
Response.End();
}
else
{ Response.Write("false");
Response.End();
}
}
}
//注册页面
<head runat="server">
<title>无标题页</title>
<script type="text/javascript" src="jss.js">
</script>
</head>
<body>
<form id="form1" runat="server">
<div style="text-align: center">
<aspabel ID="Label1" runat="server" Height="47px" Text="实现ajax技术" Width="164px"></aspabel>
<table style="width: 274px; height: 123px">
<tr>
<td style="width: 100px">
用户名</td>
<td style="width: 100px">
<input id="tsname" type="text" onkeyup="checkName(document.getElementById('tsname').value);" /></td>
</tr>
<tr>
当在用户名对话框中输入字符时 图片不改变..
刚学入门 望指教 先谢谢了