使用 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屋!
查看全文