【发布时间】:2019-06-19 05:43:55
【问题描述】:
我正在从事一个大型的有角项目。如何在不使用 jquery 的情况下滚动到角度形式的第一个无效输入?
【问题讨论】:
-
您需要为您的问题添加一个有效的 sn-p 或指向 codepen/jsfiddle 的链接 - stackoverflow.com/help/minimal-reproducible-example
标签: javascript jquery angularjs
我正在从事一个大型的有角项目。如何在不使用 jquery 的情况下滚动到角度形式的第一个无效输入?
【问题讨论】:
标签: javascript jquery angularjs
你可以这样做:-
myApp.directive('accessibleForm', function () {
return {
restrict: 'A',
link: function (scope, elem) {
// set up event handler on the form element
elem.on('submit', function () {
// find the first invalid element
var firstInvalid = elem[0].querySelector('.ng-invalid');
// if we find one, set focus
if (firstInvalid) {
firstInvalid.focus();
}
});
}
};
});
【讨论】: