日期:2014-05-16 浏览次数:20360 次
<script language="JavaScript" type="text/javascript"> /* 用来判断所选记录是否已经存在 */ $(document).ready(function(){ $("#select").change(function(){ $.getJSON("checkData.jsp", {recordID:document.getElementById("select").value}, function(data){ if(data!=null){ if(data.recordExist != 0) { alert("该记录已存在,不能重复添加!"); $("#submitBtn").hide(); } else { $("#submitBtn").show(); } } }); }); }); </script>
<%@ page language="java" pageEncoding="GBK"%> <%@ page import="net.sf.json.JSONObject" %> <jsp:useBean id="baseDao" scope="request" class="com.common.BaseDao"/> <% /* 根据传递进来的recordID来判断记录是否已存在 */ int recordID = Integer.parseInt (request.getParameter("recordID")); //获得recordID if(recordID != 0) { String sql = "SElECT count(*) FROM T_RECORDS WHERE ID="+recordID; String[][] result = null; result = baseDao.select(sql); JSONObject jo = new JSONObject(); //新建JSON对象 jo.accumulate("recordExist",result[0][0]); //将结果存入JSON对象 out.println(jo); } %>