2013-07-05 52 views
0

我試圖在一個頁面中使用Laravel,bootstrap和jquery,可悲的是我是所有人的新手。我遇到的問題是使用jquery Validation插件在錯誤的地方顯示錯誤消息,在下圖中,錯誤位置的消息被突出顯示。如您所見,每個收音機都包含在標籤標籤中,它在Bootstrap CSS中是必需的。我試圖找出消息後面插入了哪個元素,並且失敗了。任何人都可以告訴我,在所有無線電之後應該更改哪部分代碼以移動錯誤消息,以及如何?錯誤消息出現在錯誤的地方使用jQuery驗證插件

original look

"submit" button clicked

the radio part in code

validation part in code

+1

請剪切和粘貼或鍵入您的代碼到OP,**不要發佈的代碼截圖**。這讓任何人都難以重現您的問題,因爲他們必須重新輸入所有代碼。 – Sparky

回答

1

我似乎總是有同樣的問題。你可以用errorPlacement參數解決它。

$('form').validate({ 

    errorPlacement: function(error, element) { 

     // Get inputs with this name 
     var obj = $('[name="'+element.attr('name')+'"]'); 

     // Are there multiple? 
     if (obj.length > 1) { 
      // Add error after whatever the parent element is of the last one 
      error.insertAfter(obj.last().parent()); 
     } else { 
      // Default, add error after the input 
      error.insertAfter(obj); 
     } 
    } 
}); 

你必須弄清楚你想如何處理它,這只是一種方法。

演示:http://jsfiddle.net/PgAyp/