开发者

MVC toggle buttons

开发者 https://www.devze.com 2023-01-30 00:27 出处:网络
I have a group of button开发者_如何学Cs at the moment which users can select to filter out a grid. The problem is that after one of the buttons is clicked, the user does not know the current active fi

I have a group of button开发者_如何学Cs at the moment which users can select to filter out a grid. The problem is that after one of the buttons is clicked, the user does not know the current active filter that was applied. So can anybody help me to figure out how to have these group of buttons act as toggle buttons (spec is to change the button background color for active button)?

Please note this is in MVC and there is an onclick event bound to each of the buttons which calls a javascript function.


If you ar using jquery UI you could try using the button plugin configured as a checkbox


You haven't given much detail on how you've wired up click events, but in your click handler for the buttons, you could do something like this:

var button = document.getElementById("button");
button.onclick = function() {
    if (!this.style.backgroundColor) {
        this.style.backgroundColor = 'yellow';
    }
    else {
        this.style.backgroundColor = null;
    }
}

There are other ways to do this if you're using jQuery or another JS framework.

0

精彩评论

暂无评论...
验证码 换一张
取 消