$('#err input').bind('blur keyup',function() {
$(this).data('errors', "ABC " + $(this).data('err') + " " + $(this).val());
});
$('#go').click(function(){
var code = "";
$("#err input").each(function(){
code += $(this).data('errors') + "\n" || '';
});
$('#x').html(code);
});HTML:
<div id="err">
<input data-err="A" id="e-1" type="text"/>
<input data-err="B" id="e-2" type="text"/>
<input data-err="C" id="e-3" type="text"/>
</div> 如何进行验证,如果输入将为空,则不会处理此输入?
发布于 2011-08-26 12:29:08
尝尝这个
$('#go').click(function(){
var code = "";
$("#err input").each(function(){
//This condition will check for empty values
if($(this).val()){
code += $(this).data('errors') + "\n" || '';
}
});
$('#x').html(code);
});发布于 2011-08-26 12:27:01
从提交处理程序返回false将取消默认的表单提交功能。所以使用:
$('#go').submit(function(){
//do validation here
if(validationFails)return false;
});https://stackoverflow.com/questions/7199993
复制相似问题