我看了多個線程,並嘗試了各種解決方案。坦率地說,我認爲我正在失去理智。使用回車鍵作爲選項卡只使用angularjs和jqlite
我有一個ng-repeat輸入。所有需要發生的事情是,當用戶按下Enter時,它應該將焦點轉移到下一個輸入,基本上模擬標籤鍵功能。
的代碼(不完全): HTML:
<body ng-app="ap" ng-controller="con">
<table>
<tr>
<th>Name</th>
<th>Age</th>
</tr>
<tr ng-repeat='person in persons'>
<td>
<input type='text'
name="personName"
ng-model="person.name"
/>
</td>
<td>
<input type='number'
name="personName"
ng-model="person.age"
enter-as-tab
/>
</td>
</tr>
</table>
JS:
var app = angular.module("ap", []);
app.controller("con", function ($scope) {
$scope.persons = [
{ name: 'Susan', age: 1 },
{ name: 'Peter', age: 1 },
{ name: 'Jack', age: 2 }
];
});
app.directive('enterAsTab', function() {
return function (scope, element, attrs) {
element.bind("keydown keypress", function (event) {
if(event.which === 13) {
event.preventDefault();
// Go to next age input
}
});
};
});
下面是對小提琴的鏈接:fiddle
您已經嘗試了哪些解決方案? – AlexFoxGill 2014-10-09 12:54:04
我從小提琴中刪除了代碼,所以我沒有對它們的引用,但這基本上是我想實現的:[link](http://stackoverflow.com/questions/23430830/keyboard - 導航功能於angularjs表) – avn 2014-10-09 12:55:31