Java 使用AJAX、JS、JSP选择复选框时的表着色
有人能告诉我如何给整张桌子(桌子的每一行)上色吗?到目前为止,我只能给桌子的第一行上色 jsp中的我的颜色函数:-Java 使用AJAX、JS、JSP选择复选框时的表着色,java,javascript,ajax,jsp,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.bac
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;
}
}
}
假设您的HTML如下所示:-
<input id="test" type="checkbox" name="testing" />Hello World
@rcky:你有没有试过用一行或两行带append的代码?如果没有,试着运行它。@SivaCharan……。我的代码运行得很好……。唯一的问题是,它只在选中复选框时为表的第一行着色,而我想为表中的所有三行着色……。这是我无法做到的……我没有将jsp文件粘贴到这里
$("#test").click(function() {
if ($(this).is(':checked'))
{
$('tr').css("background-color", "red");
}
});