1, 引入dll : Resource\Resource\Mediinfo.AjaxControls.dll
2, 加载样式:<link href="../../Styles/excite-bike/jquery-ui-1.8.13.custom.css" rel="stylesheet" />
<link href="../../Styles/Suggester.css" rel="stylesheet" />
3, 加载 js<script src="../../Scripts/AutoCompDataCtrl.js" type="text/javascript"></script>
4, 设置页面控件 引入ScriptManager<form id="form1" runat="server">
<asp:ScriptManager ID="sm" runat="server">
</asp:ScriptManager>
CtrlTextID=" hfldZHUANGWANGJGMC" CtrlValuID="hfldZHUANGWANGJG"
隐藏绑定值:机构名称及机构编号 ,便于交互
AjaxPath="/Web References/AutoCompDataSource.asmx" ajax 路径
AjaxMethod="GetAgencyByFix" ajax 执行方法
范例:
<%//户籍地址编号----- %><input type="hidden" id="hfldHUJIDZMC" runat="server" />
<input type="hidden" id="hfldHUJIDZBH" runat="server" />
<li>
<acc:AjaxComplete ID="HuJi" runat="server" Width="270" Height="23" Watermark="输入全称或拼音码" AllowUnresolvedItems="true" CtrlTextID="hfldHUJIDZMC" CtrlValuID="hfldHUJIDZBH" AllowMulti="false" IsGanged="JiaTing,XiuYang,ZFHuJi" HasDesc="true" DescCtrl="HuJi_Desc" ExpandWidth="300" AllowedMaxItems="1" RootCSSClass="suggester" ItemCSSClass="ui-corner-all" AjaxPath="/Web References/AutoCompDataSource.asmx" AjaxMethod="GetItemsByFix" ScriptPath="/Scripts/Suggester.js?t=20131017" OnClientBeginRequest="Address.BeginRequest" OnClientItemAdded="Address.ItemAdd_HuJi" OnClientItemRemoved="Address.ItemRemovedGrad" />
</li>
选择控件中的下拉项给隐藏域中的控件赋值选中项的ID和value;
使用控件判断隐藏域中的值是否符合规则即可.
if ($.trim($("#hfldHUJIDZBH").val()) == '' || $.trim($("#hfldHUJIDZBH").val()) == '990000000000') {
top.$.messager.alert('提示信息','请输入关键字检索选择户籍地址(请从检索目中选择)!','info',function () { ExpandFun.setCtrlFocus("HuJi"); });
return false;
}
聚焦定位到控件(具体参考项目中form.js 中的定义)
ExpandFun.setCtrlFocus("HuJi");
AllowUnresolvedItems="true"
范例
<%//死胎死产原因%>
<input type="hidden" id="hfldSITAISCYY" runat="server" />
<input type="hidden" id="hfldSITAISCYYDM" runat="server" />
<acc:AjaxComplete ID="ajaxSITAISCYYDM" runat="server" Width="150" Height="23" Watermark="输入字典全称或拼音码" AjaxOnTextLength="0" AllowMulti="true" CtrlTextID="hfldSITAISCYY" CtrlValuID="hfldSITAISCYYDM" DicNumStr="4|183" RootCSSClass="suggester" AllowedMaxItems="20" ExpandHeight="200" AllowUnresolvedItems="true" ItemCSSClass="ui-corner-all" AjaxPath="/Web References/AutoCompDataSource.asmx" AjaxMethod="GetDictByFixAndDicNum" ScriptPath="/Scripts/Suggester.js" OnClientBeginRequest="ajax_AutoFinish.onBeginRequest_Dic" OnClientItemAdded="onItemAdded_DisQTSTCtrl" OnClientItemRemoved="onItemRemoved_DisQTSTCtrl" />
如果 AllowUnresolvedItems=”false” 则用户自行输入字典中不存在的项目;保存时无法给CtrlTextID=”hfldSITAISCYY” CtrlValuID=”hfldSITAISCYYDM” 这俩项赋值 只有AllowUnresolvedItems=”true”时,输入字段中不存在的项目也会给CtrlTextID=”hfldSITAISCYY” 赋值为用户实际输入项CtrlValuID=”hfldSITAISCYYDM” 会赋值-99