我有一个场景,我正在克隆文本框。然后对于每个盒子输入我对db(通过ajax调用)验证它是输入是正确还是错误。如果它输入无效我显示一个错误框,最后我有一个jquery验证器方法,检查是否有任何框有错误消息然后它引发错误和表单不发布。但问题是验证器显示所有文本框的错误消息,无论值是对还是错。
<table id="next_module" class="table">
<thead>
<th>Message Id</th>
</thead>
<tbody>
<tr id="row_0">
<td>
<input id="messge-id_0" class="valid_next_messge_module numeric messgeing_id required" name="messge-id_0" type="text" onblur="get_messge_detail($(this));" value="">
<label id="txterr_0" class="next_messge_error" style="display: none;color:red;width:0px">*</label></td>
</tr>
</tbody>
</table>
<script>
var $underscore = $("#next_module tbody tr:first");
var $clone = $underscore.clone();
$clone.attr('id', $clone.attr("id") + i );
$clone
.find("input,label")
.each(function() {
$(this).attr({
id: this.id + i,
name: this.name + i,
value:'',
src:''
});
});
$clone
.appendTo("#next_module")
.show();
i++;
</script>
<script>
function get_messge_detail(obj)
{
var messge_id = $.trim(obj.val());
var id_num = (obj.attr('id')).split('_')[1];
if(messge_id)
{
var url = "/server/messge/ajax_get_messge_detail/";
var data = {'messge_id':messge_id};
$.ajaxSetup({async:false});
$.post(url, data, function (response) {
if (response["msg"])
{
no error found
}
else
{
$("#"+(obj.attr('id'))).focus();
$("#txterr_"+ id_num).show();
}
});
}
jQuery.validator.addMethod("valid_next_messge_module", function() {
var status = false;
if (parseInt( $('.next_messge_error:visible').length) > 0)
return false;
else
return true;
}, "Please enter valid next messgeing module id.");
</script>