使用AJAX,JS,JSP选择复选框时的表着色

时间:2012-02-16 06:52:49

标签: java javascript ajax jsp

有人可以告诉我如何为整个表格(表格的每一行)着色,截至目前我只能为表格的第一行着色

我在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;
        }
    }
}

1 个答案:

答案 0 :(得分:1)

假设您的HTML如下: -

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

使用JQuery:

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