[英]How can I get the background color of one HTML/ASP row to change when a boolean is set true?
I've got a table generate on page-load that is full of data. 我在页面加载时生成了一个充满数据的表格。 When the user clicks an ID, that row needs to highlight.
当用户单击ID时,该行需要突出显示。 Right now, I've got it so that when the user clicks the ID, a boolean is set true, and then some other stuff happens.
现在,我已经知道,当用户点击ID时,布尔值设置为true,然后发生其他一些事情。 I have it set so that when the boolean is true, that row will be highlighted.
我设置它,以便当布尔值为true时,该行将突出显示。 However, this isn't happening.
但是,这种情况并没有发生。 Can you help me figure out why?
你能帮我搞清楚为什么吗?
<%
If RS.RecordCount > 0 then
Do While Not RS.EOF
if RS("ROLL_ID") = IntRollID then
boolDetailTable = true
end if
%>
<TR <% if boolDetailTable = true then %> bgcolor "#CCFF00" <%end if%>>
<a target=_top href="<% = getInfo(RS("ROLL_ID"))%>" onMouseOver="window.status='Click to get info';return true;" onMouseOut="window.status='';return true;">
<TD style="width: 9%; cursor: hand; border-right: none; align: center; vertical-align: center;"
title="Click to get info">
<font color="navy"><%= RS("ROLL_ID")%></font>
</TH>
</a>
<TD style="width=25%" style="font-size: 12pt" align="center"> <% = RS("ROLL_FINISH_DESC") %></TD>
<TD style="width=20%" style="font-size: 12pt" align="center"> <% = RS("ROLL_DIAMETER") %></TD>
<TD style="width=20%" style="font-size: 12pt" align="center"> <% = RS("ROLL_CROWN") %></TD>
<TD style="width=10%" style="font-size: 12pt" align="center"> <% = RS("ROLL_LOCKOUT_YN") %></TD>
</TR>
<%
RS.MoveNext()
Loop
end if
%>
如果你有一个,请尝试.css
tr.active{color:#CCFF00;}
For starters you need to change one of your tags in the code below - you need to start with either the <th>
or end with the </td>
as you have a mismatch. 对于初学者,您需要在下面的代码中更改其中一个标记 - 您需要以
<th>
开头或以</td>
结尾,因为您不匹配。
For this example I changed </TH>
to </TD>
在本例中,我将
</TH>
更改为</TD>
You will also notice I added an onClick(this.parent);
您还会注意到我添加了一个
onClick(this.parent);
to the <td>
到
<td>
<TD onClick="SetColor(this.parent);" style="width: 9%; cursor: hand; border-right: none; align: center; vertical-align: center;"
title="Click to get info">
<font color="navy"><%= RS("ROLL_ID")%></font>
</TD>
The OnClick
will send the elements parent - in this case the row itself ( <tr>
) to a function called SetColor(elem)
OnClick
将父元素发送 - 在这种情况下,行本身( <tr>
)发送到一个名为SetColor(elem)
的函数
Have a javascript function like this in your page: 在您的页面中有这样的javascript函数:
function SetColor(elem){
elem.style.backgroundColor = "#ff0000";
}
This should change the row to a red color for you. 这应该为您将行更改为红色。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.