【问题标题】:Table coloring on selecting checkbox using AJAX,JS,JSP使用 AJAX、JS、JSP 选择复选框时的表格着色
【发布时间】:2012-03-07 14:05:39
【问题描述】:

谁能告诉我如何给整个表格(表格的每一行)上色,到目前为止我只能给表格的第一行上色

我在jsp中的颜色函数:-

function changeColor(rowID){
        var row = document.getElementById(rowID);

        var alternateRow = document.getElementById(rowID +'_alt');  
    if(row!=null){
        if(row.style.backgroundColor == '' || row.style.backgroundColor == '#ffffff'){
            row.style.backgroundColor = "#009966";
            return;
        }
        if(row.style.backgroundColor == '#009966'){
            row.style.backgroundColor = "#ffffff";
            return;
        }    
    }
    if(alternateRow!=null){     
        if(alternateRow.style.backgroundColor == '' || alternateRow.style.backgroundColor == '#ffffff'){
            alternateRow.style.backgroundColor = "#009966";
            return;
        }
        if(alternateRow.style.backgroundColor == '#009966'){
            alternateRow.style.backgroundColor = "#ffffff";
            return;
        }
    }
}

【问题讨论】:

    标签: java javascript ajax jsp


    【解决方案1】:

    假设您的 HTML 如下:-

    <input id="test" type="checkbox" name="testing" />Hello World
    

    使用 JQuery:

    $("#test").click(function() {     
       if ($(this).is(':checked'))
        {
            $('tr').css("background-color", "red");
        }
    });
    

    【讨论】:

    • @rcky:你试过你的代码用一两行追加吗?如果没有,请尝试运行它。
    • @SivaCharan............我的代码工作正常............唯一的问题是它只为表格的第一行着色在选择复选框时,我想为表格中的所有三行着色......我无法做到......我没有在这里粘贴 jsp 文件
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-13
    • 2020-08-14
    • 1970-01-01
    • 2016-07-03
    • 2021-03-23
    • 1970-01-01
    相关资源
    最近更新 更多