读书人

改变按钮图片解决思路

发布时间: 2012-03-11 18:15:39 作者: rapoo

改变按钮图片
两个控件
CheckBox id="chkbAgree"
ASP:Button id="btnEnter"
用js方法,当checkbox选中的时候,改变button的图片。
js:
if (ckbAgree.checked) {
//改变图片样式
btnEnter.CssClass = "btnRegister";//方法无效
btnEnter.setAttribute("background-image", "url(../images/btnclose.jpg)");//方法无效
btnEnter.setAttribute("background", "url(../images/btnclose.jpg)");//方法无效
}


[解决办法]
是可以的,可能是你的图片路径有问题。另外得到id对象
是采用
document.getElementById('<%=ckbAgree.ClientID%>')
[解决办法]

HTML code
    <asp:CheckBox ID="chkbAgree" runat="server"         oncheckedchanged="chkbAgree_CheckedChanged"  AutoPostBack="true"/>    <asp:Button ID="btnEnter" runat="server" Text="Button" />
[解决办法]
错了
应该是
document.getElementById('<%=btnEnter.ClientID %>').style.backgroundImage= "url(http://dotnet.aspx.cc/Images/logoSite.gif)"

or
btnEnter.setAttribute("style", "background-image:url(../images/btnclose.jpg)");无效

读书人网 >asp.net

热点推荐