老是記不住的JS驗證...

<script language="javascript" type="text/javascript">   
      //<![CDATA[   
      function validateMonth(month) {
          if(isNaN(parseInt(month))) {
              return false;
              }
          if(month.length!=6||parseInt(month.charAt(0))>2||parseInt(month.charAt(0))<1) {
              return false;
              }
          if(parseInt(month.charAt(4))==0) {
              if(parseInt(month.charAt(5))<1) {
                  return false;
                  }
              } else if(parseInt(month.charAt(4))==1) {
               if(parseInt(month.charAt(5))>2) {
                      return false;
                      }
                  } else {
                      return false;
                      }
          return true;
          }
      function validateSalaryMonth(form) {
          var avgSalaryStartMonth = form["queryForm:startYearMonth"].value;
          var avgSalaryEndMonth = form["queryForm:endYearMonth"].value;
          if(!validateMonth(avgSalaryStartMonth)){
           alert("請輸入正確的年月!");
              return false;
          }
          if(!validateMonth(avgSalaryEndMonth)){
           alert("請輸入正確的年月!");
              return false;
          }
          return true;
          }
      //]]>   
    </script> 

 

<a4j:commandButton value="查詢" action="#{employeeIncomeTaxAction.queryIncomeTax}"
							onclick="if(!validateSalaryMonth(this.form)) return false;" reRender="showdata" />

 

<a4j:commandLink value="刪除" reRender="showdata" action="#{employeeIncomeTaxAction.deleteIncomeTax}" onclick="if (!confirm('確定刪除嗎?')){return false;}" ></a4j:commandLink>

 

<a4j:outputPanel ajaxRendered="true">
			<h:messages id="hmessage" style="display:none" showSummary="true"
				showDetail="false" />
			<script language="javascript" type="text/javascript">   
           //<![CDATA[   
           try{   
               var msg= document.getElementById("hmessage").innerHTML.replace(/<.+?>/gim,'');   
               if(msg){   
                   if(msg.length > 0){   
                       alert(msg );   
                   }   
               }   
           }catch(e){}   
           //]]>   
       </script>
</a4j:outputPanel>

 

你可能感兴趣的:(JavaScript)