我想获取数据单元格的值 <td>
如果我点击另一个<td>
同一行。
<tr ng-repeat="x in names">
<td>{{ x.Name }}</td>
<td>{{ x.Country | uppercase }}</td>
</tr>
解决它的一种方法是例如 http://jsfiddle.net/L60L3gv9/
$scope.getValueOfTD = function(x){
alert(x.Name);
}
但就我而言,我的数据单元之间没有链接。有没有办法使用标准函数(如 )获取此值?
$scope.getValueOfTD = function(){
}
任何解决方案都可以
最佳答案
您可以在 tr
上使用 ng-click
:
HTML:
<table>
<th>Column1</th>
<th>Column2</th>
<tr ng-repeat="x in names" ng-click="getValueOfTD(x)">
<td>{{ x.Name }}</td>
<td>{{ x.Country | uppercase }}</td>
</tr>
</table>
JS:
$scope.getValueOfTD = function (user) {
console.log(user.Name);
}
关于javascript - 使用 Angular 将 <td> onclick 的值获取到同一行的另一个 <td>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34262231/