-3

通过单击图像“imgAdd”,我想使用 JavaScript 将 div“divAddCustomerInfo”的可见性设置为 true。但是单击图像不起作用。我认为那是因为 JavaScript 不工作。任何人都可以帮忙吗?提前谢谢。

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
 <script type="text/javascript">
    function imgAdd_click() {
        document.getElementById("divAddCustomerInfo").style.visibility = 'visible';
    }
</script>
<div id="divCustomerBody" style="margin-left:300px; margin-top:50px;">
    <h1>Customer</h1>
    <hr style="color:gray; width:900px; margin-left: 0px;" />
    <br />
    <div id="divOperationSymbol" style="height:100px; width:900px; ">

        <div id="divAddition" onclick="divAddition_click()" style="height:100px; float:left; width:300px; " >
            <img id="imgAdd" onclick="imgAdd_click()" src="001446-3d-transparent-glass-icon-media-a-media35-add.png" style="height:70px; width:70px; display:block; margin-left:auto; margin-right:auto;" />
            <label id="lblAdd" onclick="lblADD_click()" style="color: #a6a6a6; margin-left:100px;">Add Customer</label>
        </div>

    </div>
</div>
    <div id="divAddCustomerInfo" style="visibility: hidden; margin-left:300px; margin-top:50px;">

</div>

4

3 回答 3

1

更改以下内容

<div id="divAddCustomerInfo" runat="server" visible="false" style="margin-left:300px; margin-top:50px;">

进入

<div id="divAddCustomerInfo" runat="server" style="visibility:hidden;margin-left:300px; margin-top:50px;">
于 2016-09-08T06:55:16.050 回答
0

将以下部分更新为

<div id="divAddition" onclick="divAddition_click()" style="height:100px; float:left; width:300px; " >
            <img id="imgAdd" onclick="imgAdd_click()" src="001446-3d-transparent-glass-icon-media-a-media35-add.png" style="height:70px; width:70px; display:block; margin-left:auto; margin-right:auto;" />
            <label id="lblAdd" onclick="lblADD_click()" style="color: #a6a6a6; margin-left:100px;">Add Customer</label>
        </div>
于 2016-09-08T06:53:13.337 回答
-1

它是您的代码的工作版本(见下文):您的错误:

  • 中没有括号onclick
  • 缺席visibility: hidden;_div id="divAddCustomerInfo"

<div id="divCustomerBody" style="margin-left:300px; margin-top:50px;">
    <h1>Customer</h1>
    <hr style="color:gray; width:900px; margin-left: 0px;" />
    <br />
    <div id="divOperationSymbol" style="height:100px; width:900px; ">

        <div id="divAddition" onclick="divAddition_click()" style="height:100px; float:left; width:300px; " >
            <img id="imgAdd" onclick="imgAdd_click()" src="http://www.ipac.caltech.edu/2mass/gallery/antennae.jpg" style="height:70px; width:70px; display:block; margin-left:auto; margin-right:auto;" />
            <label id="lblAdd" onclick="lblADD_click()" style="color: #a6a6a6; margin-left:100px;">Add Customer</label>
        </div>

    </div>
</div>
<div id="divAddCustomerInfo" runat="server"   style="margin-left:300px; margin-top:50px; visibility:hidden">
    Text
</div>

function imgAdd_click() {
    document.getElementById("divAddCustomerInfo").style.visibility = 'visible';
}
于 2016-09-08T06:56:14.970 回答