步驟一引入js檔案
程式碼如下:
">
"> 複製程式碼
程式碼如下:
/**
*↓↓↓↓↓價🎜>*版本:1.0
*日期:2013-03-22
*說明:
*↑↑↑↑↑↑↑↑↑↑ 🎜>$(function(){
/*1.失去焦點驗證↓↓↓*/
$("#code").blur(callback);//1.code就是你要驗證的唯一標誌的控制項ID 2.你控制項後面必須要有個接收錯誤訊息的控制項
/*2.提交時候驗證↓↓↓*/
$("#submit").click(callback);/ /你頁面的提交按鈕ID
});
/**
*↓↓↓↓↓價和提交按鈕ID要和下面保持一致
*版本:1.0
*日期:2013-03-22
*說明:
*↑↑↑↑↑↑↑↑↑*/
function callback() {
var slef=$("#code");
var code=slef.val();
var submit=$("#submit");
var flag=$("#flag").val();
if(null==code| |""==code){
slef.next().html("下載包標識不能為空!");
submit.attr("disabled",true);
return;
}else{
if(!code.match("^\w $")){
slef.next().html("標識由數字母或底線組成!");
return ;
}
slef.next().html("*");
}
$.ajax({
type:'post',
url:'. ./dictionary/checkCodeOnly.do',
data:'bean.code=' code '&bean.flag=' flag,
dataType:'json',
success:function(json){
if(json>0){
slef.next().html("此標識已存在!");
submit.attr("disabled",true);
return ;
}else{
slef.next().html("");
if(code != null && code!=""){
submit.attr("disabled",false);
}else{
submit.attr("disabled",true);
return;
}
}
},
error:function(){
alert ('驗證訊息出錯');
}
});
}
步驟三頁部分
步驟三頁部分
步驟三頁部分
下載編號下載:下載編號 |
* |
步驟四action裡的方法
程式碼如下>
/**
*
* @author ZhuangZi
* @class com.hzdracom.action.YhaoPortalsDictionaryAction
* @method checkCodeOnly
* @Directions 驗證符號3-21上午10:09:04 void
*/
public void checkCodeOnly(){
String json="";
try{
json = String.valueOf(yhaoDictionOnServicetry{
json = String.valueOf(yhaoDictionOnaryService. bean));
json=JSON.toJSONString(json);
System.out.println("json==" json);
HttpServletResponse response=ServletActionContext.getResponse(); setContentType("text/html");
response.setCharacterEncoding("utf-8");
PrintWriter out;
out = response.getWriter();
out.println(json);
out.flush();
out.close();
}catch(Exception e){
e.printStackTrace();
}
}
步驟五dao裡的方法
public int checkCodeOnly(DictionaryBean bean)throws DataAccessException,Exception { <br>Object[] sqlParams = new Object[4]; <br>int index = 0 <int index="0">String sql=""; <br>/* 驗證頁面標誌是否唯一*/ <br>if (bean.getFlag().equals("1")) { <br>sql = "select count(1) from YHAO_PORTALS_PAGE where PAGE_FLAG = ? "; <br>sqlParams[index]=bean.getCode(); <br>index ; <br>} <br>/* 驗證類型志標識是否唯一*/ <br>if (beanan .getFlag().equals("2")) { <br>sql = "select count(1) from YHAO_PORTALS_DOWNTYPE where DOWNTYPE_FLAG = ? "; <br>sqlParams[index]=bean.getCode();; ; <br>} <br>/* 驗證下載志標識是否唯一*/ <br>if (bean.getFlag().equals("3")) { <br>sql = "select count(1) from YHAO_PORTALS_DOWN where DOWN_FLAG = ? "; <br>sqlParams[index]=bean.getCode(); <br>index ; <br>} <br>if (bean.getFlag().equals("4")) { <br>if (bean.getFlag().equals("4")) { <br>if (bean.getFlag().equals("4")) { <br>sql = "select count(1) from YHAO_PORTALS_KUAI where KUAI_FLAG = ? "; <br>sqlParams[index]=bean.getCode(); <br>index ; <br>} <br>Object[] sqlParamsEnd [index]; <br>System.arraycopy(sqlParams, 0, sqlParamsEnd, 0, index); <br>int count = this.queryForInt(sql,sqlParamsEnd); <br>return count; <br>}); <br>return>}; > <br><pre class="brush:php;toolbar:false">
登入後複製