jquery根据ID填充文本框的代码示例
根据ID填充文本框的小例子。
需要引入外部jquery框架。
1,前台:
<script type="text/javascript"> /** * 根据ID填充文本框中内容 * edit by www.jbxue.com */ function func_load_remark(sr_id){ if(sr_id!=0){ $.getJSON("loadSrRemark.do?date="+new Date(), {srid:sr_id}, function(srmain){ $("#bparemark").val(srmain.bpa_remark); $("#itdremark").val(srmain.itd_remark); $("#bugremark").val(srmain.bu_remark); $("#itoremark").val(srmain.ito_remark); }); }else{ $("#bparemark").val(""); $("#itdremark").val(""); $("#bugremark").val(""); $("#itoremark").val(""); } } function check(){ if($("#srid").val()=="0"){ alert("请选择SR_ID!"); $("#srid").focus(); return false; } return true; } </script>
后台代码:
package com.aegon_cnooc.oa.admin.action; import java.io.PrintWriter; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import net.sf.json.JSONSerializer; import net.sf.json.util.JSONUtils; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import com.aegon_cnooc.framework.base.action.BaseAction; import com.aegon_cnooc.oa.admin.service.UserService; import com.aegon_cnooc.oa.ibatis.to.TuOafSrMainTO; public class LoadSrRemarkAction extends BaseAction{ private UserService userService; public ActionForward executeAction(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { String srid=request.getParameter("srid"); TuOafSrMainTO srMain=userService.getRemarkBySrId(srid); response.setContentType("application/json;charset=gbk"); response.setCharacterEncoding("gbk"); PrintWriter pw = response.getWriter(); pw.write(JSONUtils.valueToString(JSONSerializer.toJSON(srMain))); pw.flush(); return null; } public void setUserService(UserService userService) { this.userService = userService; } }
相关推荐
王练 2020-06-12
81463166 2020-05-16
Reiki 2020-05-04
82550495 2020-05-01
zcl 2020-03-04
donghongbz 2020-01-17
tangfenjuan 2019-12-02
heshanking 2019-10-29
Passerby 2019-10-28
89463661 2019-11-05
Clarence 2011-11-18
chang00 2015-06-17
xuewenke 2012-05-19
87281248 2018-03-13
zZoOoOJaVa 2018-02-19
mianhuantang 2009-12-11
srchange 2019-08-19
echoright晓戈 2011-11-21
yuqiuyao 2018-11-23