javascript - change attribute of target when click using angularJS - Stack Overflow

<ul class="todo-list"><li ng-repeat="todo in todos">{{todo.todoContent}

<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 badges
Add a ment  | 

2 Answers 2

Reset to default 4

If 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条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信