EasySearch效果,模糊查询,支持拼音(数据库中有一字段存储拼音)和字
<script type="text/javascript">
function showdata(){
var xmlHttp=null;
try { xmlHttp=new XMLHttpRequest(); }
catch (e)
{ try
{ xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); }
catch (e)
{ xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } }
var ID=document.getElementById("hgname").value;
xmlHttp.open("GET",encodeURI("easy_2.aspx?ID="+ID),false);
xmlHttp.send();
if(xmlHttp.readyState == 4){
document.getElementById("flo_div").innerHTML=xmlHttp.responseText;
}
}
function hiddiv(){
document.getElementById("flo_div").style.visibility='hidden';
}
function showdiv(){
document.getElementById("flo_div").style.visibility='visible';
}
function show(text){
document.getElementById("hgname").value=text;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div></div>
<input type="text" id="hgname" name="hgname" οnmοusedοwn="return showdiv();" οnkeyup="return showdata();" /><br />
<div id="flo_div" style="position: absolute; z-index:10; visibility:hidden; width:146px; height:200px; border:solid 1px #003366; background-color: #FFFFEE"></div>
<br />
<label>这部分内容将被遮盖这部分内容将被遮盖这部分内容将被遮盖这部分内容将被遮盖这部分内容将被遮盖</label>
</form>
</body>
public partial class easy_2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string id = Request.QueryString["ID"].ToString();
using (SqlConnection con = new SqlConnection("Server=.;database=HGSTUDY;uid=sa;pwd=yao"))
{
StringBuilder sb = new StringBuilder();
con.Open();
SqlCommand comd = new SqlCommand(string.Format("select CODE_NAME from CD_HGNAME where CODE_NAME LIKE '{0}%' OR CODE_PY like '{1}%'",id,id), con);
comd.CommandType = CommandType.Text;
Response.ContentType = "uft-8";
SqlDataReader read = comd.ExecuteReader();
while (read.Read())
{
for (int i = 0; i < read.FieldCount; i++)
sb.Append("<div style='font-size:12px' οnclick=document.getElementById('hgname').value=this.innerHTML;document.getElementById('flo_div').style.visibility='hidden'; οnmοuseοver=this.style.color='#FFFFFF';this.style.background='#003366' οnmοuseοut=this.style.color='#000000';this.style.background='#FFFFFF'>" + read[i] + "</div>");
}
Response.Write( sb.ToString());
}
}
}