我在每个单元格中都有一个输入表格,我可以通过单击按钮将记录添加到该表格。 我想专注于创建的最后一条记录的第一个输入。 我不知道这是可能的。 如果有人可以帮助我在此...Angularjs,专注于表格中的输入
function Ctrl($scope) {
$scope.adresses = [];
$scope.add = function() {
var adr = {ville:null, codePostal:null}
$scope.adresses.push(adr);
};
}
<!doctype html>
<html ng-app>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.2/angular.min.js"></script>
<script src="script.js"></script>
</head>
<body>
<div ng-controller="Ctrl" >
<button ng-click="add()"> Add </button>
<table>
<tr>
<th>ville</th>
<th>adresse</th>
<tr>
<tr ng-repeat="adresse in adresses">
<td>
<input ng-model="adresse.ville"/>
</td>
<td>
<input ng-model="adresse.codePostal"/>
</td>
<tr>
</table>
</div>
</body>
</html>
看看[这个问题](http://stackoverflow.com/questions/14833326/how在设置焦点上的输入字段),我认为它基本上做你想要的。你可以在'ng-repeat'中使用'$ last'属性来检测是否设置焦点。 – 2015-03-31 15:51:07