我在每個單元格中都有一個輸入表格,我可以通過單擊按鈕將記錄添加到該表格。 我想專注於創建的最後一條記錄的第一個輸入。 我不知道這是可能的。 如果有人可以幫助我在此...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