首页 > 唔,jQuery的点击改变class样式用angular该怎么写?

唔,jQuery的点击改变class样式用angular该怎么写?

$(function(){
    $(".sem").click(function(){
        $(".comments").hide();
        $(this).parent().next(".comments").show();
        $(".circle.active").removeClass("active");
        $(this).parent().addClass("active");
    });
});


这是jQuery的代码,我想改用angular的话,这个要怎么写呀?

angular以数据为中心,最简单的先设置class="{{classValue}}"初始值,点击后改变classValue。网上有篇文章,讲解ng-class操作的三种方法,可以参考下,希望对你有帮助:http://www.cnblogs.com/whitewolf/archive/2013/05/22/3092184.html


在你要加样式的元素上加 ng-class="{'active':classShowed}",classShowed是控制样式是否显示的变量。在controller中有$scope.classShowed bool型变量与之对应。在点击事件中控制$scope.classShowed的值(true,false)就能显示和隐藏样式了。详细自己百度 angular ng-class。

【热门文章】
【热门文章】