【发布时间】:2016-08-29 19:58:00
【问题描述】:
我的任务
创建 3 个输入,每个输入具有最大字符。长度 5 输入第 5 个字符时。在输入中,光标应在插入字符后立即跳转到下一个输入。删除输入的第一个字符时,光标应在删除该字符后立即跳转到前一个输入的末尾。
我做了什么
使用监视组创建了 3 个输入字段并将字符长度限制为 5,并且运行良好
我的问题
当输入字段达到最大字符长度 5 时,我需要将光标移动到下一个输入字段,如果第一个字符已从输入字段中删除,则光标应自动移动到上一个输入字段末尾
我的插件链接在这里https://plnkr.co/edit/Bcq6slz9gbK8r6Lm8MAh?p=preview
我的角码
var app = angular.module("task8", []);
app.controller("taskController8",["$scope", function ($scope) {
$scope.charLength=5
$scope.$watchGroup(['firstInput', 'secondInput', 'thirdInput'], function (newValue, oldValue) {
if (newValue) {
if (newValue[0].length > 5) {
$scope.firstInput = oldValue[0];
}
else if (newValue[1].length > 5) {
$scope.secondInput = oldValue[1];
newValue[2].focus();
}
else if (newValue[2].length > 5) {
$scope.thirdInput = oldValue[2];
}
$scope.charLength = 5 - newValue[0].length;
$scope.charLength = 5 - newValue[1].length;
$scope.charLength = 5 - newValue[2].length;
}
})
$scope.updateBody = function (event) {
return false;
};
}]);
【问题讨论】: