JQuery下拉框模糊查询_第1页
JQuery下拉框模糊查询_第2页
免费预览已结束,剩余1页可下载查看

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、2012-04-1014:24C#+jQuery+div实现下拉框信息提示模糊搜索结果(百度、google搜索提示框)实现效果:用户输入查询字符串,当文本框内容变化时,显示下拉框为用户提示完整信息,并可以实现选中所查信息后获得对应ID而进行更进一步的关联显示。(比如搜某一公司,选中公司后在根据公司ID获得公司产品)。推荐jQueryAutocomplete插件:(演示地址)http:/jquery.bassistance.de/autocomplete/demo/?主人博客:http:/bassistance.de/(还有好多有用的Plugins)手动实现:在输入框所在的页面:引入jquery

2、开发包:样式及脚本bodyfont:11pxarial;.suggest_link_altbackground-color:#FFFFFF;text-align:right;cursor:hand;padding:2px6px2px6px;z-index:101;.suggest_linkbackground-color:#FFFFFF;padding:2px6px2px6px;z-index:101;.suggest_link_overbackground-color:#E8F2FE;padding:2px6px2px6px;z-index:101;#search_suggestz-inde

3、x:100;position:absolute;background-color:#FFFFFF;text-align:left;border:1pxsolid#000000;#search_suggestRz-index:100;position:absolute;background-color:#FFFFFF;text-align:left;border:1pxsolid#000000;/*input*/.input_onmargin:2px8px0pt10px;height:18px;border:1pxsolid#999;background-color:#FFFFCC;.input

4、_offmargin:2px8px0pt10px;height:18px;border:1pxsolid#CCC;background-color:#FFF;.input_movemargin:2px8px0pt10px;height:18px;border:1pxsolid#999;background-color:#FFFFCC;.input_out/*height:16px;默认高度*/margin:2px8px0pt10px;height:18px;border:1pxsolid#CCC;background-color:#FFF;functionDivSetVisible(divid

5、,frameid,state)varDivRef=document.getElementById(divid);varIfrRef=document.getElementById(frameid);if(state)DivRef.style.display=block;IfrRef.style.width=DivRef.offsetWidth;IfrRef.style.height=DivRef.offsetHeight;IfrRef.style.top=DivRef.style.top;IfrRef.style.left=DivRef.style.left;IfrRef.style.zInd

6、ex=DivRef.style.zIndex-1;IfrRef.style.display=block;elseDivRef.style.display=none;IfrRef.style.display=none;/当输入框的内容变化时,调用该函数functionsearchSuggest()if($(#txtSearch).val()!=&$(#txtSearch).val()!=null)$.ajax(type:GET,url:././AJAX.aspx,data:type=searchCompany&searchText=+escape($(#txtSearch).val(),succ

7、ess:function(result)varsourceText=result.split(*);if(sourceText.length1)DivSetVisible(search_suggest,DivShim,true);/$(#search_suggest).show();$(#search_suggest).html();for(vari=0;isourceText.length-1;i+)vars=+sourceTexti.split(,)1+;$(#search_suggest).html($(#search_suggest).html()+s);$(#search_sugge

8、st).html($(#search_suggest).html()+关闭提示/div);elseDivSetVisible(search_suggest,DivShim,false);/$(#search_suggest).hide(););elseDivSetVisible(search_suggest,DivShim,false);/$(#search_suggest).hide();functionsuggestOver(div_value)div_value.className=suggest_link_over;functionsuggestOut(div_value)div_va

9、lue.className=suggest_link;functionsetSearch(obj,id)$(#txtSearch).val(obj);$(#hidCompId).val(id);$.ajax(type:GET,url:././AJAX.aspx,data:type=getCompanyJob&companyId=+id,success:function(result)$(#drpPost).empty();varsourceText=result.split(*);if(sourceText.length1)for(vari=0;isourceText.length-1;i+)

10、$(+sourceTexti.split(,)1+).appendTo(#drpPost);$(#search_suggest).html();DivSetVisible(search_suggest,DivShim,false);/$(#search_suggest).hide();HTML:/r*1TCl,r*1IIAJAX.aspx实现:AJAX.aspx.cs:stringsearchText=RequestsearchText;StringBuilderresult=newStringBuilder(100);if(!string.IsNullOrEmpty(searchText)SqlDataReaderdr=null;trydr=SqlHelper.ExecuteReader(SqlHelper.ConnectionString,CommandType.Text,selecttop20Identifier,CompanyfromUserInfowherecompanylike%+keywords+%,newSqlParameter(keywords,sea

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论