相关疑难解决方法(0)

在angular2中实现addClass和removeClass功能

我有两个ListView和GridView按钮.为了在这两个按钮之间切换,我写了JQuery,如下所示 -

<script type="text/javascript">
    $(document).ready(function () {
        $("button.switcher").bind("click", function (e) {
            e.preventDefault();
            var theid = $(this).attr("id");
            var theitems = $("ul#items");
            var classNames = $(this).attr('class').split(' ');
            if ($(this).hasClass("active")) {
                // if currently clicked button has the active class
                // then we do nothing!
                return false;
            } else {
                // otherwise we are clicking on the inactive button
                // and in the process of switching views!
                if (theid == "gridview") {
                    $(this).addClass("active");
                    $("#listview").removeClass("active");
                    // remove the list  view and change to grid …
Run Code Online (Sandbox Code Playgroud)

typescript angular

22
推荐指数
3
解决办法
8万
查看次数

标签 统计

angular ×1

typescript ×1