zoukankan
html css js c++ java
类似Google边输边搜
select.js
var
searchReq
=
createAjaxObj();
function
createAjaxObj()
{
var
httprequest
=
false
;
if
(window.XMLHttpRequest)
{
httprequest
=
new
XMLHttpRequest();
if
(httprequest.overrideMimeType)
httprequest.overrideMimeType(
'
text/xml
'
);
}
else
if
(window.ActiveXObject)
{
//
IE
try
{
httprequest
=
new
ActiveXObject(
"
Msxml2.XMLHTTP
"
);
}
catch
(e)
{
try
{
httprequest
=
new
ActiveXObject(
"
Microsoft.XMLHTTP
"
);
}
catch
(e)
{
}
}
}
return
httprequest
}
var
id_txt;
//
text_write
var
id_hdn;
var
id_div;
//
div_show
function
searchSuggest(sid,v_txt_id,v_hdn_id,v_div_id,v_args)
{
if
(document.getElementById(
''
+
v_txt_id
+
''
).value
==
document.getElementById(
''
+
v_hdn_id
+
''
).value)
{
return
;
}
document.getElementById(
''
+
v_hdn_id
+
''
).value
=
document.getElementById(
''
+
v_txt_id
+
''
).value;
id_txt
=
v_txt_id;
id_hdn
=
v_hdn_id;
id_div
=
v_div_id;
if
(document.getElementById(
''
+
id_txt
+
''
).value.length
>
0
)
{
var
str
=
escape(document.getElementById(
''
+
id_txt
+
''
).value);
url
=
"
../WebService/Sv_Search.aspx?sid=
"
+
sid
+
"
&t=
"
+
new
Date().getTime()
+
"
&args=
"
+
v_args
+
"
&search=
"
+
str;
searchReq.open(
"
get
"
,url);
searchReq.onreadystatechange
=
handleSearchSuggest;
searchReq.send(
null
);
}
else
{
document.getElementById(
''
+
id_div
+
''
).innerHTML
=
""
;
document.getElementById(
''
+
id_div
+
''
).style.display
=
"
none
"
;
}
}
function
handleSearchSuggest()
{
if
(searchReq.readyState
==
4
)
{
var
ss
=
document.getElementById(
''
+
id_div
+
''
);
ss.innerHTML
=
""
;
s0
=
searchReq.responseText.length;
if
(s0
>
0
)
{
xmldoc
=
searchReq.responseXML;
var
message_nodes
=
xmldoc.getElementsByTagName(
"
message
"
);
var
n_messages
=
message_nodes.length;
if
(n_messages
<=
0
)
{
document.getElementById(
''
+
id_div
+
''
).innerHTML
=
""
;
document.getElementById(
''
+
id_div
+
''
).style.display
=
"
none
"
;
}
else
{
document.getElementById(
''
+
id_div
+
''
).style.display
=
"
block
"
;
for
(i
=
0
;i
<
n_messages;i
++
)
{
var
suggest
=
'
<div onmouseover="javascript:suggestOver(this);"
'
;
suggest
+=
'
onmouseout="javascript:sugggestOut(this);"
'
;
suggest
+=
'
onclick="javascript:setSearch(this.innerHTML);"
'
;
suggest
+=
'
class="suggest_link">
'
+
message_nodes[i].getElementsByTagName(
"
text
"
)[
0
].firstChild.data
+
'
</div>
'
;
ss.innerHTML
+=
suggest;
}
}
}
else
{
document.getElementById(
''
+
id_div
+
''
).innerHTML
=
""
;
document.getElementById(
''
+
id_div
+
''
).style.display
=
"
none
"
;
}
}
else
{
//
alert('网络连接失败');
}
}
function
suggestOver(div_value)
{
div_value.className
=
'
suggest_link_over
'
;
}
function
sugggestOut(div_value)
{
div_value.className
=
'
suggest_link
'
;
}
function
setSearch(div_value)
{
document.getElementById(
''
+
id_hdn
+
''
).value
=
div_value;
document.getElementById(
''
+
id_txt
+
''
).value
=
div_value;
document.getElementById(
''
+
id_div
+
''
).innerHTML
=
""
;
document.getElementById(
''
+
id_div
+
''
).style.display
=
"
none
"
;
}
SearchText.ascx
<%
@ Control Language
=
"
C#
"
AutoEventWireup
=
"
true
"
CodeFile
=
"
SearchText.ascx.cs
"
Inherits
=
"
Controls_SearchText
"
%>
<
script
language
="javascript"
src
="../Scripts/search.js"
></
script
>
<
input
runat
="server"
id
="txtSearch"
name
="txtSearch"
type
="text"
autocomplete
="off"
/>
<
input
runat
="server"
id
="hdnSearch"
name
="hdnSearch"
type
="hidden"
/>
<
br
><
div
runat
="server"
id
="search_suggest"
style
="display:none;"
class
="search_suggest"
></
div
>
<
style
>
/**/
/*
----------类似Google边输边搜样式----------
*/
.suggest_link
{
}
{
background-color
:
#fff
;
padding
:
2px 6px 2px 6px
;
cursor
:
default
;
}
.suggest_link_over
{
}
{
background
:
#e8e2fe
;
padding
:
2px 6px 2px 6px
;
cursor
:
pointer
;
}
.search_suggest
{
}
{
z-index
:
999
;
position
:
absolute
;
color
:
gray
;
background-color
:
#ffffff
;
text-align
:
left
;
border
:
1px solid gray
;
}
/**/
/*
-------------------------------------------
*/
</
style
>
<!--
SearchText.ascx.cs
-->
<%
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
public
partial class Controls_SearchText : System.Web.UI.UserControl
{
#region
property
private
string
_Sid
=
""
;
private
string
_Args
=
""
;
public
bool ReadOnly
{
set
{
if
(value
==
true
)
{
this.txtSearch.Attributes.Add(
"
readonly
"
,
"
readonly
"
);
}
else
{
this.txtSearch.Attributes.Remove(
"
readonly
"
);
}
}
}
public
string
Width
{
set
{
this.txtSearch.Style[
"
width
"
]
=
value;
this.search_suggest.Style[
"
width
"
]
=
value;
}
}
public
string
CssClass
{
set
{
this.txtSearch.Attributes[
"
class
"
]
=
value;
}
}
///
<
summary
>
///
用于指向所要查询的数据源,必填
///
</
summary
>
public
string
Sid
{
set
{
this._Sid
=
value;
}
}
///
<
summary
>
///
传递查询参数,可填
///
</
summary
>
public
string
Args
{
set
{
this._Args
=
value;
}
}
#endregion
protected void Page_Load(
object
sender, EventArgs e)
{
this.txtSearch.Attributes[
"
onpropertychange
"
]
=
"
javascript:searchSuggest(
"
+
this._Sid
+
"
,this.id,'
"
+
this.hdnSearch.ClientID
+
"
','
"
+
this.search_suggest.ClientID
+
"
','
"
+
this._Args
+
"
');
"
;
}
}
%>
Sv_Search.aspx.cs
public partial class WebService_Sv_Search : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
this.Response.ContentType = "text/xml";
string strSearchTarget = this.Request.QueryString["sid"].Trim();
string strSearchTime = this.Request.QueryString["t"].Trim();
string strSearchArgs = this.Request.QueryString["args"].Trim();
string[] arrSearchArgs = null;
if (!strSearchArgs.Equals(string.Empty))
{
arrSearchArgs = strSearchArgs.Split('|');
}
string strSearchString = this.Request.QueryString["search"].Trim();
DataTable dt = null;
SvSearchDal objDal = new SvSearchDal();
dt = objDal.GetCompletionList(int.Parse(strSearchTarget), strSearchTime, arrSearchArgs, strSearchString);
StringBuilder xml = new StringBuilder();
xml.Append("
<?
xml version=\"1.0\" encoding=\"utf-8\"
?>
\n");
xml.Append("
<
root
>
\n");
for(int i=0; i
<
dt
.Rows.Count; i++)
{
xml.Append("<message id
=\""
+ Convert.ToString(i + 1) + "\"
>
\n");
xml.Append("
<
text
>
" + dt.Rows[i][0].ToString().Trim() + "
</
text
>
\n");
xml.Append("
</
message
>
\n");
}
xml.Append("
</
root
>
");
this.Response.Write(xml.ToString());
this.Response.Flush();
this.Response.Close();
}
}
查看全文
相关阅读:
CSS让DIV按照背景图片的比例缩放,并让背景图片填充整个元素(转)
判断浏览器
$.each遍历json对象
jq塞入不同状态html的写法 switch (defaults.type)
vue资料
第三方登录
获取一个项目的所有接口
接口工具调研
go自动化测试平台
压测工具 vegeta
原文地址:https://www.cnblogs.com/ding0910/p/1222655.html
最新文章
Servlet 3.0异步特性初探
AI行为树的工作原理
从今天起转移阵地到博客园
Java中初始化的相关问题
第四届中国高校计算机大赛——团体程序设计天梯赛总结
Hacker Cups and Balls Gym
Color Length UVA
Partitioning by Palindromes UVA
G
2018Ec-Final比赛总结
热门文章
PTA 7-12(图) 社交网络图中结点的“重要性”计算 最短路
PTA 7-10(图) 旅游规划 最短路问题
7-1 寻找大富翁 PTA 堆排序
Lighting System Design UVA
手机连接,打开chrome
去除img默认的边框
css 文本两行显示,超出省略号表示
js 从URL上获取参数
微信分享代码 和 统计
h5向上翻页图标晃动动画,css固定h5向上翻页图标在页面上
Copyright © 2011-2022 走看看