使用jQuery切换焦点到带有验证错误的标签 [英] Using jQuery to switch to focus a tab with a validation error
本文介绍了使用jQuery切换焦点到带有验证错误的标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试让jQuery在发现错误的情况下切换至选项卡.现在,它将发现一个错误,但不会转到带有错误的选项卡.
I'm trying to get jQuery to switch to a tab if it finds an error on it. Right now it will find an error but won't go to the tab with the error.
这是我目前拥有的代码
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery('#Form').validate({
ignore: ".ignore",
invalidHandler: function(){
jQuery("#tabs").tabs("select", jQuery("#Form .input-validation-error").closest(".tab-pane").get(0).id);
}
});
});
jQuery('.Submit').click(function(evt) {
evt.preventDefault();
jQuery('#Form').submit()
});
</script>
推荐答案
尝试
jQuery('#userEditForm').validate({
ignore: ".ignore",
invalidHandler: function(e, validator){
if(validator.errorList.length)
$('#tabs a[href="#' + jQuery(validator.errorList[0].element).closest(".tab-pane").attr('id') + '"]').tab('show')
}
});
演示:小提琴
这篇关于使用jQuery切换焦点到带有验证错误的标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文