2011-05-10 53 views
0

我有一個表單,當狀態選擇列表發生更改時,狀態生效日期需要是必填字段。jquery:當選擇列表值發生更改時,需要輸入日期字段

function checkStatuses(){  
    $('.status').each(function(){ 
     thisStatus = $(this).val().toLowerCase(); 
     thisOrig_status = $(this).next('.orig_status').val().toLowerCase(); 
     target = $(this).parents('td').nextAll('td:first').find('.datepicker'); 

     if (thisStatus == thisOrig_status ) 
     { 
     target.val(''); 
     } 
     else if(thisStatus == 'production' || thisStatus == 'production w/o appl') 
     { 
     target.val('<cfoutput>#dateformat(now(), "mm/dd/yyyy")#</cfoutput>').focus(); 
     alert('The Status Effective Date is required.'); 
     return false; 
     } 
     else 
     { 
     target.val('<cfoutput>#dateformat(now(), "mm/dd/yyyy")#</cfoutput>'); 
     return false; 
     } 
    }); 
} 

返回false並不妨礙我的表單提交反正。上述表單正在被另一個函數調用像這樣:

return checkStatuses();

回答

1

你的功能,現在正在返回什麼。唯一的返回語句是在jQuery循環中。 A return false基本上是到$.each()循環的休息。然後返回到主函數(checkStatuses()),該函數在沒有任何返回語句的情況下到達代碼塊的末尾。有一個回報變量可能會有所幫助:

function checkStatuses(){ 
    var result = true; //assume correct unless we find faults 

    $('.status').each(function(){ 
     thisStatus = $(this).val().toLowerCase(); 
     thisOrig_status = $(this).next('.orig_status').val().toLowerCase(); 
     target = $(this).parents('td').nextAll('td:first').find('.datepicker'); 

     if (thisStatus == thisOrig_status ) 
     { 
     target.val(''); 
     } 
     else if(thisStatus == 'production' || thisStatus == 'production w/o appl') 
     { 
     target.val('<cfoutput>#dateformat(now(), "mm/dd/yyyy")#</cfoutput>').focus(); 
     alert('The Status Effective Date is required.'); 
     result = false; //set to false meaning do not submit form 
     return false; 
     } 
     else 
     { 
     target.val('<cfoutput>#dateformat(now(), "mm/dd/yyyy")#</cfoutput>'); 
     result = false; //set to false meaning do not submit form 
     return false; 
     } 
    }); 
    return result; //return the result of the checks 
} 
+0

哦,男人,我太親近了! :) 感謝您的幫助。 – HPWD 2011-05-11 13:12:14

+0

@ dlackey哈哈它發生了!祝你好運 – Chad 2011-05-11 13:13:59

相關問題