问题描述
<tr ng-repeat='goods in $data'> <td contenteditable=’true’> {{goods.name}} </td> </tr> 对td内容进行修改 现在我想获取点击td 弹出当前td的内容。 怎么实现。
问题解答
回答1:<tr ng-repeat='goods in $data'> <td ng-click='show($event)' contenteditable='true' > {{goods.name}} </td> </tr> function show(e){ alert(e.target.innerText)}ng-model是双向数据绑定可以随时获取值,但ng-model只作用于input标签和一些文本标签上。所以根据你的需求,只能通过dom去获取文本上的内容,但不是实时的,这一些修改的值下次点击才会得到。回答2:
<tr ng-repeat='goods in $data track by $index'> <td ng-click=consoleSomeThing($index)> {{goods.name}} </td> </tr>//js部分$scope.consoleSomeThing=function(index){ //具体看你的$data结构了,复杂点的就去遍历吧,反正重点是拿到对应的索引index console.log($data[index].goods.name)}回答3:
使用name = angular.element($event.target).text()