首页上一页 1 下一页尾页 1 条记录 1/1页
异步查找数据
发表在C#图书答疑
2011-05-05
是否精华
是
否
版块置顶:
是
否
怎么在当前页面输入名字,然后从另一个页面返回与之名字匹配的提示:
响应的页面程式
protected void Page_Load(object sender, EventArgs e)
{
string[] a = new string[30];
a[0] ="Anna";
a[1] ="Brittany";
a[2] ="Cinderella";
a[3] ="Diana";
a[4] ="Eva";
a[5] ="Fiona";
a[6] ="Gunda";
a[7] ="Hege";
a[8] ="Inga";
a[9] ="Johanna";
a[10] ="Kitty";
a[11] ="Linda";
a[12] ="Nina";
a[13] ="Ophelia";
a[14] ="Petunia";
a[15] ="Amanda";
a[16] ="Raquel";
a[17] ="Cindy";
a[18] ="Doris";
a[19] ="Eve";
a[20] ="Evita";
a[21] ="Sunniva";
a[22] ="Tove";
a[23] ="Unni";
a[24] ="Violet";
a[25] ="Liza";
a[26] ="Elizabeth";
a[27] ="Ellen";
a[28] ="Wenche";
a[29] = "Vicky";
string st = Request.QueryString["q"].ToString().ToUpper();
if (st.Length > 0)
{
string hint = "";
for (int i = 0; i < 30;i++ )
// foreach (string s in a)
{
if (st == a[i].ToString().Substring(0,st.Length).ToUpper())
//problem!
{
if (hint == "")
{
hint = a[i];
}
else
{
hint = hint + "," + a[i];
}
}
//Response.Write(a[i]);
// Response.Write("<br/>");
}
if (hint == "")
{ Response.Write("no suggestion"); }
else
Response.Write(hint);
输入节目代码:
<script type="text/javascript">
function showHint(str)
{
var xmlhttp;
if (str.length==0)
{
document.getElementById("txtHint").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","/reptxt.aspx?q="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>
<h3>请在下面的输入框中键入字母(A - Z):</h3>
<form action="">
姓氏:<input type="text" id="txt1" onkeyup="showHint(this.value)" />
</form>
<p>建议:<span id="txtHint"></span></p>
响应的页面程式
protected void Page_Load(object sender, EventArgs e)
{
string[] a = new string[30];
a[0] ="Anna";
a[1] ="Brittany";
a[2] ="Cinderella";
a[3] ="Diana";
a[4] ="Eva";
a[5] ="Fiona";
a[6] ="Gunda";
a[7] ="Hege";
a[8] ="Inga";
a[9] ="Johanna";
a[10] ="Kitty";
a[11] ="Linda";
a[12] ="Nina";
a[13] ="Ophelia";
a[14] ="Petunia";
a[15] ="Amanda";
a[16] ="Raquel";
a[17] ="Cindy";
a[18] ="Doris";
a[19] ="Eve";
a[20] ="Evita";
a[21] ="Sunniva";
a[22] ="Tove";
a[23] ="Unni";
a[24] ="Violet";
a[25] ="Liza";
a[26] ="Elizabeth";
a[27] ="Ellen";
a[28] ="Wenche";
a[29] = "Vicky";
string st = Request.QueryString["q"].ToString().ToUpper();
if (st.Length > 0)
{
string hint = "";
for (int i = 0; i < 30;i++ )
// foreach (string s in a)
{
if (st == a[i].ToString().Substring(0,st.Length).ToUpper())
//problem!
{
if (hint == "")
{
hint = a[i];
}
else
{
hint = hint + "," + a[i];
}
}
//Response.Write(a[i]);
// Response.Write("<br/>");
}
if (hint == "")
{ Response.Write("no suggestion"); }
else
Response.Write(hint);
输入节目代码:
<script type="text/javascript">
function showHint(str)
{
var xmlhttp;
if (str.length==0)
{
document.getElementById("txtHint").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","/reptxt.aspx?q="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>
<h3>请在下面的输入框中键入字母(A - Z):</h3>
<form action="">
姓氏:<input type="text" id="txt1" onkeyup="showHint(this.value)" />
</form>
<p>建议:<span id="txtHint"></span></p>