<ul class="todo-list">
<li ng-repeat="todo in todos">{{todo.todoContent}}<span class="pull-right glyphicon glyphicon-check" ng-class="{checked:todo.done}" ng-click="todoCheck(todo)" title="check this todo">check</span></li>
</ul>
Now I want change title attribute to "uncheck this todo" and text "check" to "checked" when I click the span element to check target todo.
Anyone can help here. Thanks very much.
example fiddle
<ul class="todo-list">
<li ng-repeat="todo in todos">{{todo.todoContent}}<span class="pull-right glyphicon glyphicon-check" ng-class="{checked:todo.done}" ng-click="todoCheck(todo)" title="check this todo">check</span></li>
</ul>
Now I want change title attribute to "uncheck this todo" and text "check" to "checked" when I click the span element to check target todo.
Anyone can help here. Thanks very much.
example fiddle
Share Improve this question asked Sep 13, 2013 at 8:18 tjfdfstjfdfs 73910 silver badges26 bronze badges2 Answers
Reset to default 4If you want more fine grained control over the element you clicked, you can do this by using the $event in the ng-click handler.
like
ng-click="todoCheck($event, todo)"
I have used jquery to set the title and content and updated your fiddle.
Here is the updated fiddle
$scope.todoCheck = function ($event, todo) {
var spanElement = $event.srcElement; $(spanElement).attr('title', "uncheck this todo"); $(spanElement).html("checked"); todo.done = !todo.done;
};
<li ng-repeat="todo in todos">
{{todo.todoContent}}
<span class="pull-right glyphicon glyphicon-check"
ng-class="{checked:todo.done}" ng-click="todoCheck(todo)"
title="{{!todo.done && 'check this todo' || 'uncheck this todo'}}">
{{!todo.done && 'check' || 'checked'}}
</span>
</li>
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745101593a4611306.html
评论列表(0条)