请教imagebutton修改图片url的问题
写了个很简单的imagebutton,实现功能:
1. 点击后修改图片。比如点击前,imagebutton图片为‘.../Clickme.png',点击后图片为'.../ThankYouClicking.png'.
2. 触发后台一个方法;
现在用javascript去写,但是点击后并没有改变图片,请教大家问题处在哪里呢?谢谢!
<script type="text/javascript">
function changeImage()
{
document.getElementById("ImageTestButton1").setAttribute("ImageUrl", "~/Images/ThankYouClicking.png");
}
</script>
<asp:ImageButton ID="ImageTestButton1" runat="server" ImageUrl="~/Images/ClickMe.png" OnClick="ImageButton1_Click" OnClickClient="changeImage()"/>javascript
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script type="text/javascript">
function $(id) {
return document.getElementById(id);
}
window.onload = function () {
var a = $("ImageTestButton1");
a.setAttribute("src", "2.gif");
};
function change() {
var a = $("ImageTestButton1");
a.setAttribute("src", "1.jpg");
};
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ImageButton ID="ImageTestButton1" runat="server" />
<input type="button" id="test" value="测试" onclick="change()" />
</div>
</form>
</body>
</html>
ImageTestButton1.ImageUrl="~/Images/ThankYouClicking.png";