不能让文本在悬停时显示下划线

本文关键字:显示 下划线 悬停 文本 不能 | 更新日期: 2023-09-27 17:53:09

我有这样的代码:

e.Row.Attributes["onmouseover"] = "this.style.textDecoration='underline';";
e.Row.Attributes["onmouseout"] = "this.style.textDecoration='';";

这样,当我将鼠标悬停在一行上时,其中的所有文本都会加下划线。但这行不通。我也试过这个:

e.Row.Attributes.Add("onmouseover", "this.style.textDecoration='underline'");

这个也不能用

编辑:此代码有效。除了风格,还有别的选择吗?textDecoration类似于这个我可以使用,那不需要css?

e.Row.Attributes["onmouseover"] = "this.style.fontWeight='bold';";

不能让文本在悬停时显示下划线

为什么不使用css呢?

.table-hover tr td:hover {
    text-decoration: underline;
}
.table-hover tr td {
     text-decoration: none;
}

然后将该类应用到您的表(我猜您正在使用GridView):

<asp:GridView CssClass="table-hover">
   .....
</asp:GridView>

你可以这样写:

e.Row.Attributes.Add("class", "cell-hoverunderline");

然后添加如下的CSS样式:

.cell-hoverunderline:hover {
    text-decoration: underline;
}