0
<script language="javascript" type="text/javascript">
function resize()
{ 
//alert("ok");
       var e = document.GetElementById("ImageEdit");
      e.style.width = "500px";

}
</script>


 <asp:Image ID="ImageEdit" runat="server"  BorderWidth="4"  Width="120px" Height="120px"  name="Image1"  /></td></tr>

 <input id="Button1" type="button" value="button"  onclick="resize();" />

Why doesn't ImageEdit change width ?

4

2 回答 2

2

It is:

getElementById()

and not:

GetElementById()

Can't believe I didn't spot that earlier.

Full code sample:

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script language="javascript" type="text/javascript">
        function resize() {
            var x = '<%= ImageEdit.ClientID %>';
            alert(x);
            var e = document.getElementById('<%= ImageEdit.ClientID %>');
            e.style.width = "500px";
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <asp:Image ID="ImageEdit" runat="server" BorderWidth="4" Width="120px" Height="120px" name="Image1" />

        <input id="Button1" type="button" value="button" onclick="resize();" />
    </form>
</body>
</html>
于 2012-12-23T04:17:27.170 回答
1

Seany84 的回答是正确的,但是如果您打算在您的项目中使用大量的 java 脚本,我建议您使用jQuery。它使使用 java 脚本在公园里散步!

<head runat="server">
    <script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
    <script language="javascript" type="text/javascript">
        $(document).ready(function () {
            $("#Button1").click(function () {
                $("#ImageEdit").width("500px");
            });
        });
    </script>
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:Image ID="ImageEdit" runat="server" BorderWidth="4" Width="120px" Height="120px" name="Image1" />
    <input id="Button1" type="button" value="button" />
    </form>
</body>
于 2012-12-23T17:54:48.603 回答