给两个按钮,一个放大,一个缩小,JS如何获取Image里面ID。
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<asp:Image ID="pic" runat="server" Height="500px" Width="500px" ImageUrl='<%# Eval ("JieGuo") %>' />
</ItemTemplate>
</asp:Repeater>
<asp:Button ID="Button1" runat="server" Text="放大" OnClientClick="large()" />
<asp:Button ID="Button2" runat="server" Text="缩小" onclick="Button2_Click" />
[code=JScript][/code]
function large() {
var image = document.getElementById("<%=pic.ClientID%>");
image.width = image.width / 0.8;
image.height = image.height / 0.8;
}
function simg() {
var image = document.getElementById("<%=pic.ClientID%>");
image .width = image .width * 0.8;
image .height = image .height * 0.8;
}
求解答。 谢谢了....
------解决方案--------------------------------------------------------
通过网页源码看看他的 id都是什么 有什么规律 然后在获取
------解决方案--------------------------------------------------------
你应该这样
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
{
Image m = e.Item.FindControl("pic") as Image;
Button Button1 = e.Item.FindControl("Button1") as Button;
Button Button2 = e.Item.FindControl("Button2") as Button;
if (m != null && Button1 != null && Button2 != null)
{
Button1.OnClientClick = "large('" + m.ClientID + "');return false;";
Button1.OnClientClick = "simg('" + m.ClientID + "');return false;";
}
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
</head>
<body>
<form runat="server" id="form1">
<asp:Repeater ID="Repeater1" runat="server" OnItemDataBound="Repeater1_ItemDataBound">
<ItemTemplate>
<asp:Image ID="pic" runat="server" Height="500px" Width="500px" ImageUrl='<%# Eval("JieGuo") %>' />
<asp:Button ID="Button1" runat="server" Text="放大" />
<asp:Button ID="Button2" runat="server" Text="缩小" />
</ItemTemplate>
</asp:Repeater>
</form>
</body>
</html>
function large(x) {
var image = document.getElementById(x);
image.width = image.width / 0.8;
image.height = image.height / 0.8;
}
function simg(x) {
var image = document.getElementById(x);
image .width = image .width * 0.8;
image .height = image .height * 0.8;
}