jQuery Validation Plugin错误放置在与输入框相同的行上

时间:2016-01-08 07:15:04

标签: jquery html jquery-validate

我正在尝试在与输入相同的行上显示验证错误消息。

例如: 网站名称:|输入框|此字段是必需的(jQuery插件显示错误)

下面是我的html结构和jQuery代码的小提琴。有人可以帮帮忙吗? https://jsfiddle.net/ebyoqmgs/

  errorPlacement: function(error, element) {
    error.appendTo( element.parent("div").next() );   }

它仍然看起来像这样。不知道我做错了什么。

Errrors displayed on a new line

1 个答案:

答案 0 :(得分:0)

的javascript

class

HTML代码

((sold>0 && sold <999)) 2>/dev/null && echo "ok" || echo "Error, Qty Sold Must be Positive Integer"

样式表

<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.min.js"></script>
<script type="text/javascript">
 $(function() {
   $("#new-site-form").validate({
     rules: {
       siteName: "required",
       contactName: "required",
       contactNumber: {
         required: true,
         //email: true //replace with phone validation
       },
       contactEmail: {
        required: true,
        email: true
       },
       address1: {
        required: true,
       },
       city: "required",
       state: "required",
       zipCode: "required",
       //survey-date: "required",
       frpmAmount: {
        required: true,
        number: true,
       },   
    },

     errorPlacement: function(error, element) {
      error.appendTo( element.parent("div").next() );
    }
   });
 });
 </script>