专注于下一个元素

Focus on the next element

本文关键字:元素 下一个 专注      更新时间:2023-09-26

我的js中有这一行:

 $('input')[$('input').index(this)+9].focus();
我想专注于下一个元素,

但是当执行此行时,我聚焦和下一个元素,但我有此错误:

错误: [$rootScope:inprog] $apply已在进行中 http://errors.angularjs.org/1.3.6/$rootScope/inprog?p0=%24apply 在REGEX_STRING_REGEXP(角度.js:63) 在开始阶段(角度.js:14706) 在范围.$get。范围.$apply (角度.js:14450) at link.setTemplate (mtxCalendar.js:23) at link.initTemplate (mtxCalendar.js:28) at HTMLInputElement.(mtx日历.js:62) at HTMLInputElement.jQuery.event.dispatch (jquery.js:4409) at HTMLInputElement.jQuery.event.add.elemData.handle (jquery.js:4095) at Object.jQuery.event.trigger (jquery.js:4324) at HTMLInputElement.(jquery.js:4875)

 scope.pressButton = function (val) {
            if (val === 'cross') {
                $('#ui-datepicker-div').hide();
            } else {
                if($.datepicker._lastInput.className.split(' ')[0] === 'champs_returnDate')  {
                    $('#ui-datepicker-div').hide();
                } else{
                    if(!scope.$$phase) {
                        $('input')[$('input').index(this)+9].focus();
                    }
                }
            }
        };
你需要

通过执行 $timeout() 来延迟执行

$timeout(function(){
    $('input')[$('input').index(this)+9].focus();
})