2017-03-01 82 views
0
<?php 
    for ($i=0; $i < $total_vehicles; $i++) { 
      $id=$edtVehicle[$i]->id; 
      $chasis=$edtVehicle[$i]->chasis; 
?> 

// HTML内容 ”novs [] []“ 想用jQuery验证来验证它如何验证NAME =“novs [78] []使用jQuery验证?

<div class="controls content contold"> 
    <input type="hidden" name="hid_novs[]" value="<?php echo $id;?>"> 
    <input type="text" name="novs[<?php echo $id;?>][]" id="novs_<?php echo $i;?>" value="<?php echo $chasis;?>"> 
    <button type="button" class="removebtn"><i class="fa fa-times"></i></button> 
    <span class="span_error"></span> 
    </div> 

    <?php 
         } 
?> 

jQuery验证

$("#add_user_form").validate({ 
      "novs[]":{ required:true, }, 
      messages: { "novs[]":{ required : "Please fill this value" }, } 
    }); 
+0

你的jQuery在哪里? – JustBaron

+0

$( “#add_user_form”)来验证({ “novs []”:{ 需要:真, }, 消息:{ “novs []”:{ 必需的: “请填写该值” }, } –

+0

更新你的问题 – JustBaron

回答

0

完全希望这将有助于你得到ID

$('.removebtn').click(function() { 
    //console.log($(this).siblings('.removebtn')); 
    //console.log($(this).siblings("input").attr('id')); 
    var found = false; 
    $(this).siblings("input").each(function (i, name) { 
     // Check if field is empty or not 
     console.log(name); 
     if (!found && jQuery(name).val() == '') { 
      alert('Please enter value') 
      found = true; 
     }; 
    }); 
    return !found; 
}); 

Fiddle

+0

这是如何回答OP问题的? – JustBaron

+0

从我的代码中他可以得到id或name他可以验证 –

+0

我想验证它的文本框是空的然后获取验证消息,但在这里,我通过文本框的名称是在关联数组中,所以验证无法捕获它。 –

0

我解决了这个问题,现在解决了,谢谢。

$("input[name^='novs_'").each(function(){ 
       $(this).rules("add", { 
       required: true, 
       messages: { 
        required: "Fill a valid value" 
       } 
      }); 
      });