<asp:DataList ID="DataList1" runat="server" RepeatColumns="1" CssClass="news" >
<ItemStyle VerticalAlign="Top" />
<ItemTemplate>
<table>
<tr style="vertical-align:top" >
<td >
<asp:LinkButton id="btnSelect" Text=<%# DataBinder.Eval(Container.DataItem,"newsTitle") %> CommandName="edit" runat="server" Width="150px" Height="10px" Font-Overline="false"/>
</td>
<td width="20px">
<asp:Label ID="Label1" runat="server" Text=<%# DataBinder.Eval(Container.DataItem,"newsTime","{0:yyyy-MM-dd}") %> Width="60px" Height="10px"></asp:Label>
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList></div>function dzLinkColor()
{
document.getElementById("btnSelect").ForeColor="Red";
document.getElementById("Label1").ForeColor="Red";
}我在<tr 后面加了onmousemove="dzLinkColor()" 没有效果,请问应该怎么做???
<ItemStyle VerticalAlign="Top" />
<ItemTemplate>
<table>
<tr style="vertical-align:top" >
<td >
<asp:LinkButton id="btnSelect" Text=<%# DataBinder.Eval(Container.DataItem,"newsTitle") %> CommandName="edit" runat="server" Width="150px" Height="10px" Font-Overline="false"/>
</td>
<td width="20px">
<asp:Label ID="Label1" runat="server" Text=<%# DataBinder.Eval(Container.DataItem,"newsTime","{0:yyyy-MM-dd}") %> Width="60px" Height="10px"></asp:Label>
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList></div>function dzLinkColor()
{
document.getElementById("btnSelect").ForeColor="Red";
document.getElementById("Label1").ForeColor="Red";
}我在<tr 后面加了onmousemove="dzLinkColor()" 没有效果,请问应该怎么做???
function dzLinkColor()
{
document.getElementById("btnSelect").style.color="Red";
document.getElementById("Label1").style.color="Red";
}
document.getElementById("Label1").ForeColor="Red";
属性名字不对,js和asp。net里面的不是一回事。
document.getElementById("Label1").style.color="Red";
document.getElementById("Label1").style.color="Red"; 里面的btnSelect,Label1都是服务器端得id,所以获取控件都得不到。js获取控件应该用客户端控件id。
首先在数据绑定以后向客户端输出clientid
protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
{
Response.Write("<script type='text/javascript'> var btnSelectCilentId='" + DataList1.Controls[0].FindControl("btnSelect").ClientID + "'</script>");
}
然后在客户端就可以获取了document.getElementById(btnSelectCilentId).style.color="Red";