jsp自动完成下拉提示框

后台action的方法

public String getProductinfosToJson(){
 		String chars = ServletActionContext.getRequest().getParameter("chars");
 		Map<String,Object> map = new HashMap<String, Object>();
 		map.put("code", chars);
 		List list = manager.findProductinfosByMap(map);
 		return this.renderJsonList(list);
 	}


前台页面的关键代码

<input type="text" name="pcode" id="pcode"/>
<script language="js" type="text/javascript">
 					$("#pcode").coolautosuggest({
 						url:"productinfo!getProductinfosToJson.action?chars=",
 						showThumbnail:false,
 						showDescription:true,
 						//photopath:'${ctx}/upload/productinfo/',
 						onSelected:function(result){
 						  // Check if the result is not null
 						  if(result!=null){
 						    $("#pid").val(result.id); 
 						    $("#pname").val(result.name);
 						    $("#pcode").val(result.code);
 						    $("#pmoney").val(result.money);
 						   
 						   $("#imgShowExpertPhoto2").attr('src',"${ctx}/upload/productinfo/" + result.photo );
 						  }
 						  else{
 						    $("#pid").val(""); 
 						    $("#pcode").val("");
 						    $("#pname").val(""); 
 						    $("#pmoney").val("");
 						    $("#imgShowExpertPhoto2").attr('src',"${ctx}/upload/common/NoExpertPhoto.JPG");
 						  }
 						}
 					});
 					function clearImg(){
 						 $("#imgShowExpertPhoto2").attr('src',"${ctx}/upload/common/NoExpertPhoto.JPG");
 					}
 					function addDetail(){
 						var pid=$("#pid").val();
 						if(pid==""||pid==null){
 							alert("请选择有效的商品,在进行添加!");
 							return false;
 						}
 						$.ajax({
 						  type: 'POST',
 						  url: "setmealProductinfo!save.action",
 						  dataType: "from",
 						  data:$("#inputForm").serialize(),//"inputForm";
 						  success: function(msg){
 						  	if(msg.length>0){
 						  		alert(msg);
 						  		$("#inputForm")[0].reset();
 						  		 $("#imgShowExpertPhoto2").attr('src',"${ctx}/upload/common/NoExpertPhoto.JPG");
 						  	}
 						  	else
 						   window.location.href="setmeal!view.action?id=${id}";
 						  }
 						});
 					}
 					function delSetmealProductinfo(id){
 						$.ajax({
 						  type: 'POST',
 						  url: "setmealProductinfo!delete.action?id="+id,
 						  success: function(){
 						   window.location.href="setmeal!view.action?id=${id}";
 						  }
 						});
 					}
 				</script>
 


我在1.2.0版本的jquery中加入了json的解析方法。(jquery.js)
附件中有我做的java例子和原来的Demo。
参考网址:http://www.open-lib.com/Type/159-1.jsp ,有大量好用的jquery控件
参考网址:http://wenku.baidu.com/view/b7dadf4fc850ad02de804184.html,将list转为json。

 

有图有真相

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值