温伟的程序生活,一步一个脚印
自己会努力,做真正独一无二的温伟!无论前方有多难,我都不会放弃... 每一篇日志,都是我的积累,全是我的原创!

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" onmousedown="return showdiv();" onkeyup="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' onclick=document.getElementById('hgname').value=this.innerHTML;document.getElementById('flo_div').style.visibility='hidden';  onmouseover=this.style.color='#FFFFFF';this.style.background='#003366' onmouseout=this.style.color='#000000';this.style.background='#FFFFFF'>" + read[i] + "</div>");
            }
            Response.Write( sb.ToString());
        }      
    } 
}

posted on 2009-03-24 07:44  winvay  阅读(428)  评论(0编辑  收藏  举报