function checkCode(){
var temp;
$.ajax({
cache:false,
async:false,
type:"POST",
url:"doJSP/doCode.jsp",
data:"rand="+code.val(),
success:function(rand){
if(parseInt(code.val())==parseInt(rand) && code.val()!=""){
right(code,codeError);
codeError.html(" 驗證碼輸入正確.");
temp=true;
}else{
temp2="false";
wrong(code,codeError);
codeError.html(" 驗證碼輸入錯誤,可以點擊圖片刷新.");
temp=false;
}
}
});
return temp;
關鍵這個屬性: async:false
默認為true,表示異步請求,改為false同步請求,就能取到上面代碼temp的值...困擾蠻久的問題,開始還以為是js的作用域,測試無果,終于找到原來是$.ajax沒設置好- -!