2012-06-15 111 views
0

可以anynone告訴我如何爲下面的驗證碼編寫自定義驗證器?我是jquery的新手,並沒有寫任何自定義驗證器。我需要使用這個自定義驗證器以及默認驗證器。我試過寫,但沒有奏效。請幫助Jquery - 需要幫助使用驗證碼

challengeField = $("input#recaptcha_challenge_field").val(); 
responseField = $("input#recaptcha_response_field").val(); 
var html = $.ajax({ 
type: "POST", 
url: "recaptcharesponse.jsp", 
data: "recaptcha_challenge_field=" + challengeField + "&recaptcha_response_field=" +  responseField, 
async: false 
}).responseText; 
//console.log(html); 
$("#prtCnt").html(""); 
return true; 
} else { 
$("#prtCnt").html("<font color='#D31145'>Please try again.The characters you entered  didn't match the word verification</font>"); 
Recaptcha.reload();           
return false; 
} 

感謝

+2

這篇文章的標題是非常誤導 – musefan

回答

0
 challengeField = $("input#recaptcha_challenge_field").val(); 
     responseField = $("input#recaptcha_response_field").val(); 

     $.ajax({ 
     type: "POST", 
     async: false, 
     url: "recaptcharesponse.jsp", 
data: {"recaptcha_challenge_field" :challengeField,"recaptcha_response_field":responseField), 
     success:function(msg){ 
      if(msg == "something from server that captcha is ok"){ 
       //catcha is ok do wat you want 
      }else{ 
      $("#prtCnt").html("<font color='#D31145'>Please try again.The characters you entered didn't match the word verification</font>"); 
     Recaptcha.reload(); 
    } 

    },error:function(){ 


    } 

     }); 
+0

BTW的HTML屬性字體折舊使用範圍或別的東西 – coolguy

+0

感謝了很多。我需要將這些代碼放在document.ready中嗎?點擊提交按鈕時如何使其可行。請指教 – user1020713

+0

我將此代碼添加到提交按鈕單擊事件中,驗證有效,但其他字段的驗證不起作用。 – user1020713