简体   繁体   English

单击按钮显示Div

[英]Show Div on Button Click

I am trying to show a loading div on button click, but it is not working at the moment. 我正在尝试在单击按钮时显示一个加载div,但目前无法正常工作。

Javascript : Javascript:

<script type="text/javascript">
        $(document).ready(function (e) {      
            $('#BtnSend').click(function () {
                $('#<%= loading.ClientID %>').toggle("slow");
            });
        });
    </script>

Div: DIV:

<div id="loading" class="Loading" runat="server" visible="false">
  <div class="loadingImg">
    <img src="../Images/loading.gif" alt="loading" />
    </div>
  </div>

button: 按钮:

<asp:Button ID="BtnSend" runat="server" Text="SEND" 
            onclick="BtnSend_Click" CssClass="pressbutton2" Height="36px" ClientIDMode="Static" />

Also how can I call the same javascript code in the jsfiddle above within code (c#)? 另外,如何在代码(c#)中的上述jsfiddle中调用相同的javascript代码?

You have to select jQuery version from left menu, jsFiddle does not support to interpret asp.net code and generate html as asp.net engine do. 你必须选择从左侧菜单的jQuery版本,的jsfiddle并not支持解释asp.net代码和生成html作为asp.net发动机做。

在此处输入图片说明

Live Demo 现场演示

$(document).ready(function (e) {
    $('#BtnSend').click(function () {
        $('#loading').slideToggle("slow");
    });
});

If you are trying to do same in asp.net and your BtnSend is server control which does not have ClientIDMode set to static then you will need to use ClientID to bind event. 如果您试图在asp.net中执行相同的操作,并且您的BtnSend是服务器控件,并且没有将ClientIDMode设置为static那么您将需要使用ClientID绑定事件。

$(document).ready(function (e) {
    $('#<%= BtnSend %>').click(function () {
        $('#<%= loading.ClientID %>').slideToggle("slow");
    });
});

The ClientID value is set to the value of the ID property. ClientID值设置为ID属性的值。 If the control is a naming container, the control is used as the top of the hierarchy of naming containers for any controls that it contains, Reference . 如果该控件是一个命名容器,则该控件将用作其包含的任何控件Reference的命名容器层次结构的顶部。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM