2017-02-18 67 views
0

我使用jQuery驗證,當我提交表單時,它只顯示一個必填字段,並且只在我點擊它們時顯示其他人,以及下一個。jQuery的奇怪行爲驗證

這是劇本和身體:

jQuery(function() { 
     $("#form1").validate({ 
      rules: { 
       Yritys: { 
        required: true, 
        minlength: 3 
       }, 
       Henkilönimi: { 
        required: true, 
        minlength: 3 
       }, 
       Asema_yrityksessa: { 
        required: true, 
        minlength: 3 
       }, 
       Puhelin_Nr: { 
        required: true, 
        minlength: 3 
       }, 
       e_Mail: { 
        required: true, 
        minlength: 3 
       }, 
       Keskustelun_aihe: { 
        required: true, 
        minlength: 10 
       }, 
       messages: { 
        Yritys: { 
         required: "You must enter something", 
         minlength: "You must enter more than 3 characters" 
        }, 
        Henkilönimi: { 
         required: "You must enter something", 
         minlength: "You must enter more than 3 characters" 
        }, 
        Asema_yrityksessa: { 
         required: "You must enter something", 
         minlength: "You must enter more than 3 characters" 
        }, 
        Puhelin_Nr: { 
         required: "You must enter something", 
         minlength: "You must enter more than 3 characters" 
        }, 
        e_Mail: { 
         required: "You must enter something", 
         minlength: "You must enter more than 3 characters" 
        }, 
        Keskustelun_aihe: { 
         required: "You must enter something", 
         minlength: "You must enter more than 10 characters" 
        } 
       } 
      }, 

     }); 

    }); 


<div class="divInfo"> 
     <form id="form1"> 
      <span>Yritys:</span><br /> 
      <input id="Yritys" type="text" required /><br /> 
      <span>Henkilönimi:</span><br /> 
      <input id="Henkilönimi" type="text" required /><br /> 
      <span>Asema yrityksessa:</span><br /> 
      <input id="Asema_yrityksessa" type="text" required /><br /> 
      <span>Puhelin Nr:</span><br /> 
      <input id="Puhelin_Nr" type="text" required /><br /> 
      <span>e-Mail:</span><br /> 
      <input id="e_Mail" type="text" required /><br /> 
      <span>Keskustelun aihe:</span><br /> 
      <textarea id="Keskustelun_aihe" maxlength="140" style="width:300px;height:150px;" required>Enter Text Here...</textarea><br /> 
      <span style="color:red; margin-left:0;">Keskustelun aihe max 140 merkkia</span> 
      <div id="textarea_feedback" style="opacity:0.5"></div> 
      <div class="butt"><pre style="font-size:x-large">Vahvista varaus klikkamalla tässä>>>>>>>>>>>>><button id="submit" type="submit" name="appointment" value="" class="btn-warning" /></pre></div> 

     </form> 
    </div> 

爲什麼會出現這種情況?它可以工作,但不能正常工作。我找不到解決方案。

編輯:

發生這種情況:

enter image description here

+0

* 「跆拳道是怎麼回事」 *〜請不要因此使用咒罵語,縮略語,文字說話,還是什麼,但正確的英語語法。編輯。謝謝。 – Sparky

+0

對不起,我陷入了困境 – MicroDev

回答

1

爲什麼會出現這種情況?它的工作原理,但它不能正常工作...

MUST有考慮驗證每一個輸入name屬性,且name是可以從.validate()rules對象引用的唯一的事。

$("#form1").validate({ 
    rules: { 
     Yritys: {  // <- this must be the NAME 
      required: true, 
      minlength: 3 
     }, 
     Henkilönimi: { // <- this must be the NAME 
      .... 

...我無法找到解決辦法

Official Documentation: Markup recommendations -

委託項目:A '名' 屬性是必需的所有投入要素需要驗證,而插件將不會工作沒有這個。


您還一不小心把的rulesmessages對象,它應該是兄弟姐妹。

$("#form1").validate({ 
    rules: { 
     .... 
    }, 
    messages: { 
     .... 
    } 
}); 

DEMOjsfiddle.net/2o9Lxkej

+0

我改了id的名字,仍然沒有工作:/ – MicroDev

+0

@MicroDev,你也不小心把'messages'放在rules中。解決這個,它的工作原理:http://jsfiddle.net/2o9Lxkej/ – Sparky

+0

我想它應該工作,但它不在我的視覺工作室,我甚至從小提琴中複製代碼,它仍然無法正常工作。生病只是繼續沒有驗證,但你的答案是正確的 – MicroDev