简体   繁体   English

当布尔值设置为true时,如何获取一个HTML / ASP行的背景颜色?

[英]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">&nbsp; <% = RS("ROLL_FINISH_DESC") %></TD>
    <TD style="width=20%" style="font-size: 12pt" align="center">&nbsp; <% = RS("ROLL_DIAMETER") %></TD>
    <TD style="width=20%" style="font-size: 12pt" align="center">&nbsp; <% = RS("ROLL_CROWN") %></TD>
    <TD style="width=10%" style="font-size: 12pt" align="center">&nbsp; <% = 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.

相关问题 如何使用 HTML、CSS 和 JavaScript 根据值更改行的背景颜色? - How can I change the background color of a row based on the value using HTML, CSS and JavaScript? 如何根据其中一个单元格的值更改动态填充的表格行的背景颜色? - how can I change background color of dynamically filled table row based on the value of one of the cells? 使用 div 作为选项卡,如何更改单击的背景颜色并将其他颜色设置回原始颜色? - Using divs as tabs how can I change the background color on the one clicked and set the others back to original? 在 html select 中悬停或选择项目时,如何避免更改背景颜色? - How can I avoid change of background color when hoovering or selecting an item in a html select? 如何更改html中单个列的背景颜色? - How can I change the background color for a single column in html? 如何更改 index.html 中 body 的背景颜色? - How can I change the background color of the body in index.html? 我如何更改选定的背景颜色输入 html/js - How i can change the selected background color input html/js 如何更改所选选项的背景颜色? (HTML) - How can I change the background color of a selected option? (HTML) 如何更改 HTML 仪表的背景颜色? - How Can I change the background color of HTML meter? 如何更改 HTML 中的按钮背景颜色? - How can i change a button background color in HTML?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM