0

フォームを持っていますが、ステータス選択リストが変更された場合、ステータス有効日を必須フィールドにする必要があります。

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();

4

1 に答える 1

1

あなたの関数は今何も返していません。あなたが持っている唯一の return ステートメントは、jQuery ループにあります。Areturn falseは基本的に$.each()ループの中断です。次にcheckStatuses()、 return ステートメントなしでコードブロックの最後に到達するメイン関数 ( ) に戻ります。戻り変数があると役立つ場合があります。

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
}
于 2011-05-10T20:34:09.447 に答える