JavaScript验证适用于Firefox但不适用于Chrome

时间:2013-02-07 04:26:04

标签: javascript google-chrome firefox cross-browser

我很难过,已经花了好几个小时。你们能告诉我什么是错的吗? 在表单末尾的开头尝试了onsubmit。将其更改为onChange并onClick仍然是同一个问题。

如果我写一个onclick函数,我也无法通过Submit按钮说出感谢信息,因为它禁用了onsubmit

<script type="text/javascript">
<!--
 // Form validation code will come here.
 function validate()
 {

 if( document.myForm.name.value == "" )
{
 alert( "Please provide your name!" );
 document.myForm.name.focus() ;
 return false;
 }
  if( document.myForm.email.value == "" )
 {
  alert( "Please provide your Email!" );
  document.myForm.email.focus() ;
 return false;
  }
 if( document.myForm.phone.value == "" ||
       isNaN( document.myForm.phone.value ) ||
       document.myForm.phone.value.length != 5 )
 {
   alert( "Please provide a phone number so we can reach you." );
   document.myForm.phone.focus() ;
    return false;
   }
return( true );
 }
   //-->
 </script>

<div class="iphorm-outer">
    <form class="iphorm" action="send_contact.php" name="myForm" method="post"  >
        <div class="iphorm-wrapper">
        <div class="iphorm-inner">
               <div class="iphorm-message"></div>
               <div class="iphorm-container clearfix">
                    <!-- Begin Name element -->
                    <div class="element-wrapper name-element-wrapper clearfix">
                        <label for="name">Name <span class="required">(required)</span></label>
                        <div class="input-wrapper name-input-wrapper">
                            <input class="name-element" id="name" type="text" name="name" />
                        </div>
                    </div>
                    <!-- End Name element -->
                    <!-- Begin Email element -->
                    <div class="element-wrapper email-element-wrapper clearfix">
                        <label for="email">Email <span class="required">(required)</span></label>
                        <div class="input-wrapper email-input-wrapper">
                            <input class="email-element" id="email" type="text" name="email" />
                        </div>
                    </div>
                    <!-- End Email element -->
                    <!-- Begin Phone element -->
                    <div class="element-wrapper phone-element-wrapper clearfix">
                        <label for="phone">Phone</label>
                        <div class="input-wrapper phone-input-wrapper">
                            <input class="phone-element" id="phone" type="text" name="phone" />
                        </div>
                    </div>
                    <!-- End Phone element -->
                    <!-- Begin Message element -->
                    <div class="element-wrapper message-element-wrapper clearfix">
                        <label for="message">Message <span class="required">(required)</span></label>
                        <div class="input-wrapper message-input-wrapper clearfix">
                            <textarea class="message-element" id="message" name="message" rows="7" cols="45"></textarea>
                        </div>
                    </div>
                    <!-- End Message element -->

                    <!-- Begin Submit button -->
                    <div class="button-wrapper submit-button-wrapper clearfix">
                        <div class="loading-wrapper"><span class="loading">Thank YOU, message sent.</span></div>
                        <div class="button-input-wrapper submit-button-input-wrapper">
                            <input class="ka-form-submit" type="submit" name="contact" onclick="return(validate())" value="Submit"/>
                        </div>
                    </div>
                    <!-- End Submit button -->
               </div>
           </div>
       </div>
    </form>

有人可以帮我写一个函数来禁用提交按钮,除非函数验证是真的吗?

2 个答案:

答案 0 :(得分:0)

一切似乎都很好。尝试使用CTRL + F5刷新页面以清除浏览器的缓存。

答案 1 :(得分:0)

在浏览器高级设置中启用脚本调试,然后尝试