如何在加载时隐藏表格,然后在按钮点击时显示它

时间:2016-06-09 06:21:52

标签: javascript jquery asp.net

您好我正在尝试实现隐藏并显示表格。加载页面表时应隐藏,当我点击按钮时,它必须可见。为此,我在div下创建了一个表,并创建了一个按钮并创建了脚本函数。         这是与div的表      //表格的div                                                                                                                                                                                                                                                                                               公司名称                                                     公司地址                                                     公司电话号码                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

按钮代码,

<asp:Button ID="AddMore_Button" runat="server" Text="Add More" class="btn btn-primary" OnclientClick="AddMore_Button"/>   //button for displaying table

当我点击按钮时没有任何反应。         这是脚本,

<script>
            $(document).ready(function () {
                $('#AddMoreDetails').hide()
                $('#AddMore_Button').click(function () {
                    $("#AddMoreDetails").fadeToggle('fast');
                });
            });
            </script> 

While page loading table is hiding but when I click button it is not triggering. Any help..??

3 个答案:

答案 0 :(得分:2)

您编写的代码工作正常:https://jsfiddle.net/n3n82epr/

FieldTemplate

也许你的HTML代码里面有一些不正确的标签。您可以使用以下网址查看您的信息页:https://validator.w3.org/

答案 1 :(得分:0)

您的代码应该可以正常运行。该表将在页面加载时可见,直到脚本运行。因此,最好在表格中添加样式display:none

答案 2 :(得分:0)

您的代码运行正常,请检查您指定的ID /类名称

    $(document).ready(function(){
     $('p').hide();
          $("button").click(function(){
            $("p").fadeToggle('fast');
    });
});