error: function (xhr) {
$.each(xhr.responseJSON.errors,function(key) {
console.log(xhr.responseJSON.errors);
return key<2;
});
},
上面的函数向我返回以下结果:
并且我输入的字段具有相同的名字civil_no efirst和esecond
如果字段名称在json响应中,我想将输入边框变成红色。
我尝试了以下类似操作,但是它不起作用。
error: function (xhr) {
var arr = [ "efirst","esecond","civil_no"];
$.each(xhr.responseJSON.errors,function(key,value,i) {
if(xhr.responseJSON.errors=arr[i]){
$( "input[name=" arr[i]]).removeclass('border border-dark');
$( "input[name=" arr[i] ).addClass('errorClass');
return key<1;
}
});
},
console.log(key); //返回efirst,esecond,civil_no