简体   繁体   English

如何使表在加载时保持隐藏,然后在单击按钮时显示它

[英]How to keep a table hidden on load and then show it on button click

Hi I am trying to achieve the hiding and showing the table. 嗨,我试图实现隐藏和显示表。 while loading the page table should be hide and when I click button it has to visible. 在加载页面表时应该隐藏起来,当我单击按钮时它必须可见。 for that I have created a table under div and created a button and created script function. 为此,我在div下创建了一个表,并创建了一个按钮并创建了脚本函数。 Here is table with div //div for table Name of Company Address of Company Company Phone Number 这是带有div // div的表,该表的公司名称公司地址公司电话号码

Code for button, 按钮代码,

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

when I click the button nothing happens. 当我单击按钮时,什么也没有发生。 Here the script, 这是脚本

<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..??

the code you wrote works fine: https://jsfiddle.net/n3n82epr/ 您编写的代码效果很好: https//jsfiddle.net/n3n82epr/

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

Maybe your HTML code has some incorrect tags inside. 也许您的HTML代码中包含一些不正确的标记。 You can check your page with : https://validator.w3.org/ 您可以使用: https : //validator.w3.org/检查您的页面。

Your code should work fine. 您的代码应该可以正常工作。 The table will be visible on page load till the scripts run. 该表将在页面加载时可见,直到脚本运行为止。 So its better to add a style display:none to table. 因此,最好在表中添加样式display:none

your code works fine, please check your id/class name that you are specifying 您的代码工作正常,请检查您指定的ID /类名

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

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

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