使用多种颜色突出显示 [英] Using multiple colors for highlighting

查看:137
本文介绍了使用多种颜色突出显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个示例代码来突出显示表的特定单元格.有没有办法同时切换颜色或同时使用多种颜色?

I have this example code to highlight specific cells of a table. Is there a way to switch colors or use multiple colors at the same time?

我需要在这里实现两件事. 1)我希望能够在单击参数组之前将参数组(或单个参数)的颜色设置为前端的某种颜色.最多5种颜色就足够了. 2)参数去哪个颜色并不重要.颜色可以随机分配.我对这个问题进行了重新编辑,以使其更清楚.

I need to achieve two things here. 1) I'd like to be able to set the color of the parameter groups (or parameters individually) to a certain color on the front-end before I click them. Up to 5 colors would be enough. 2)It is not important with parameter goes which color. Colors can be assigned randomly. I reedited this question to make it clearer.

这是该项目的小提琴页面: http://jsfiddle.net/max33/kjcyu3yb/

Here is the fiddle page for the project: http://jsfiddle.net/max33/kjcyu3yb/

$('.selector').each(function() {
    $(this).on('click', check); 
});
    $('.all').each(function() {
       $(this).on('click', all); 
    });

function all(event) {
    
        if($(this).is(':checked')){  $("input:checkbox:not(:checked)",$(this).parents('form')).not(this).prop("checked","checked");
    } else {
        $("input:checkbox(:checked)",$(this).parents('form')).not(this).prop("checked","");
    }
    
    //$('.selector').prop("checked", this.name === "SelectAll");
    
    check(event);
}

function check(event) {
    var checked = $(".selector:checked").map(function () {
        return this.name
    }).get()
    $('td').removeClass("highlight").filter(function () {
        return $.inArray($(this).text(), checked) >= 0
    }).addClass("highlight")
    if ($(this).is(".selector"))
        $('.all').not(this).prop("checked", false)

}



 

 

推荐答案

您可以为每个表单元素使用不同的类.就像我对x使用highlight-x一样.然后在将通用highlight类添加到所有选定元素之后,我为X添加了额外的类.您可以使用不带参数的removeClass一次删除所有类.它将删除该项目的所有类.检查此小提琴.从第一个表格中全选.您将使用red突出显示所有X.如果这不符合您的要求,请告诉我.

You can use different classes for each form element. Like I have used highlight-x for x. Then after adding general highlight class to all selected elements, I am adding extra class for X. You can remove all classes at once using removeClass with no parameters. It will remove all of the item's classes. Check this fiddle. Select all from first form. You will see all X are highlighted using red. If this doesn't go with your requirement then let me know.

这篇关于使用多种颜色突出显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆