在Web应用程序中,我为鼠标悬停和鼠标输出编写JavaScript,以便更改颜色。当按钮处于datalist控制时,它不工作,当按钮在datalist控件之外时,它工作正常。这是我的代码,请帮帮我。
<script type="text/javascript" >
function changeImage()
{
document.getElementById("btnView").style.background = "#AD1F13";
}
function changeImage1()
{
document.getElementById("btnView").style.background = "#005594";
}
</script>
<asp:DataList ID="dtlstMagazine" class='tableborder' runat ="server" Width ="100%"
onitemdatabound="dtlstMagazine_ItemDataBound"
onitemcommand="dtlstMagazine_ItemCommand">
<ItemTemplate >
<div style="text-align:left; " class="item-title" >
<asp:LinkButton Font-Underline ="false" ID="ltrlTitle" CommandName="Redirect" CommandArgument='<%# Eval("titleid") %>' Font-Bold ="true" Font-Size ="Medium" runat="server" Text ='<%# Eval("Title") %>'></asp:LinkButton>
</div>
<asp:Button ID="Btn_CR1" runat="server" Text="Continue Reading" CssClass='button3' onMouseOver="changeImage()" onMouseOut="changeImage1()" /> </ItemTemplate> </asp:DataList>
答案 0 :(得分:0)
实际上,您需要引用列表中的按钮来更改其属性。您可以通过将javascript方法更改为:
来完成此操作function changeImage(obj)
{
obj.style.background = "#AD1F13";
}
和你的aspx:
<asp:Button ID="Btn_CR1" runat="server" Text="Continue Reading" CssClass='button3' onMouseOver="changeImage(this)" onMouseOut="changeImage1(this)" />