.directive("entertab", function () {
return {
link: function (scope, element, attrs, ngModel) {
element.on('keydown', function (event) {
var key = event.which || event.keyCode;
if (key == 13) {
var parent = $(element).parent()[0].localName == "div" ? $(element).parent():$(element).parent().parent(); // 依階層結構自行調整寫法
for (var i = 1; i <= 30; i++) { // 避開ng-hide,最多找30次,不然就放棄
parent = $(parent).next($(parent)[0].localName);
if (parent.length==0) break;
if ($(parent).attr("class") != "ng-hide") {
var nextchild = $(parent).find('input:not(.ng-hide,:disabled, [readonly="readonly"], [disabled="disabled"]),select:not(:disabled, [readonly="readonly"], [disabled="disabled"]),button:not(:disabled, [disabled="disabled"])');
if (nextchild.length > 0) {
$(nextchild).first().focus();
event.preventDefault();
break;
}
}
}
}
});
}
}
})
沒有留言:
張貼留言