当前位置: 代码迷 >> Web前端 >> jquery自动婚配
  详细解决方案

jquery自动婚配

热度:16   发布时间:2013-07-16 22:38:04.0
jquery自动匹配

?引入<link rel="stylesheet" type="text/css" href="${ctx}/css/jquery.autocomplete.css" />

<script type="text/javascript" src="${ctx}/js/jquery.autocomplete.js"></script>

?

<td align="left">
							<div class="selectDeptDict" style="z-index: 200">
								<input id="deptName"  value="" style="width:145px;"/>
							</div>
							<input id="deptCode" type="hidden" value="" />
						</td>

?

//autoComplete  
$(function() {
       //jason自符串
       	var tempJsonStr = '${dictDepartmentJson}';
	var dictDepartmentList = eval('(' + tempJsonStr + ')');
	var dictDepartmentArr = new Array(dictDepartmentList.length);
	
	for(var i=0;i<dictDepartmentList.length;i++){
		var tempArr = new Array(2);
		tempArr[0] = dictDepartmentList[i].deptName;
		tempArr[1] = dictDepartmentList[i].deptCode;
		dictDepartmentArr[i] = tempArr;
	}
	
	$( "#deptName" ).autocomplete({
	      data: dictDepartmentArr,
	      onItemSelect: function(item) {
	          $( "#deptName" ).val( item.value );
	          $( "#deptCode" ).val( item.data );
	      }
	});
});

?

  相关解决方案