js 判斷表單是否為空和是否是有效數字


判斷是否為空和是否是有效數字

 
         
<s:form name='form' onsubmit="return myCheck()" method="post" action="add">
    <table>
            <tr>
                <td><s:textfield key="label.productName" name="product.name" /></td>
            </tr>
            <tr>
                <td><s:textfield key="label.productPrice" name="product.price" /></td>
            </tr>
            <tr>
                <td>
                        <s:submit key="label.add" ></s:submit>
                </td>
            </tr>
        </table>
</s:form>
<script type="text/javascript">
 function myCheck(form)
            {
               for(var i=0;i<document.form.elements.length-1;i++)
               {

                var vari = document.form.elements[i];
                if(vari.name==="product.price"&&vari){
                if(isNaN(vari.value)){
alert("price 不是數字");
        return false;
}
}
                  if(document.form.elements[i].value=="")
                  {
                     alert("當前表單不能有空項");
                     document.form.elements[i].focus();
                     return false;
                  }


               }
               return true;
              
            }

</script>
 
         

 

 
        


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM