Home > Web Front-end > JS Tutorial > jquery struts verify unique identification (public method)_jquery

jquery struts verify unique identification (public method)_jquery

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-05-16 17:39:13
Original
1337 people have browsed it
Step 1: Import the js file
Copy the code The code is as follows:

< ;script language="javascript1.2" src="">


Step 2 public js file dictionary.js
Copy code The code is as follows:

/**
*↓↓↓↓↓↓↓↓↓↓
*Author: ZhuangZi
*Class name: Public method initialization
*Function: Public method initialization
*Details: Public method initialization
*Version: 1.0
*Date: 2013-03-22
*Description:
*↑↑↑↑↑↑↑↑↑↑
*/
$(function(){
/*1. Lost focus verification↓↓↓*/
$("#code").blur(callback);/ /1.code is the control ID of the only sign you want to verify 2. There must be a control behind your control that receives error information
/*2. Verify when submitting ↓↓↓*/
$("# submit").click(callback);//Submit button ID of your page
});
/**
*↓↓↓↓↓↓↓↓↓↓
*Author: ZhuangZi
*Class name: Verify unique identification public method
*Function: Unique verification
*Details: Unique identification ID and submit button ID must be consistent with the following
* Version: 1.0
* Date: 2013-03-22
* Description:
*↑↑↑↑↑↑↑↑↑↑
*/
function callback() {
var slef=$( "#code");
var code=slef.val();
var submit=$("#submit");
var flag=$("#flag").val();
if(null==code||""==code){
slef.next().html("The download package ID cannot be empty!");
submit.attr("disabled" ,true);
return;
}else{
if(!code.match("^\w $")){
slef.next().html("Identified by alphanumeric letters Or composed of underscores!");
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("This identifier already exists!");
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('Verification information error');
}
});
}

Step 3 page part
Copy code The code is as follows:



                                                       Download logo:
  id="code" name="yhaoPortalsDownBean.downFlag" cssClass="textfrom" cssStyle="width:150px;" maxlength="200"/>
                                                    ;* 🎜>



Copy code

The code is as follows:

/**
*
* @author ZhuangZi
* @class com.hzdracom.action.YhaoPortalsDictionaryAction
* @method checkCodeOnly
* @Directions Verify unique identification public method
* @date 2013- 3-21 10:09:04 AM void
*/
public void checkCodeOnly(){
String json="";
try{
json = String.valueOf(yhaoDictionaryService.checkCodeOnly( bean));
json=JSON.toJSONString(json);
System.out.println("json==" json);
HttpServletResponse response=ServletActionContext.getResponse();
response. setContentType("text/html");
response.setCharacterEncoding("utf-8");
PrintWriter out;
out = response.getWriter();
out.println(json);
out.flush();
out.close();
}catch(Exception e){
e.printStackTrace();
}
}

Method in step five
Copy code The code is as follows:

 public int checkCodeOnly(DictionaryBean bean)throws DataAccessException,Exception { <br>Object[] sqlParams = new Object[4]; <br>int index = 0 ; <br>String sql=""; <br>/* Verify whether the page flag is unique*/ <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>/* Verify whether the type flag is unique*/ <br>if (bean.getFlag().equals("2")) { <br>sql = "select count(1) from YHAO_PORTALS_DOWNTYPE where DOWNTYPE_FLAG = ? "; <br>sqlParams[index]=bean.getCode(); <br>index ; <br>} <br>/* Verify whether the download log identifier is unique*/ <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>sql = "select count(1) from YHAO_PORTALS_KUAI where KUAI_FLAG = ? "; <br>sqlParams[index]=bean.getCode(); <br>index ; <br>} <br>Object[] sqlParamsEnd = new Object[index]; <br>System.arraycopy(sqlParams, 0, sqlParamsEnd, 0, index); <br>int count = this.queryForInt(sql,sqlParamsEnd); <br>return count; <br>}&lt ;/PRE> <br><PRE>

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template