【问题标题】:Functionality When Hiding Div Not Working Correctly隐藏 Div 无法正常工作时的功能
【发布时间】:2012-03-22 08:27:11
【问题描述】:

我在页面上有以下(简要)概念:

我有 5 个复选框,根据选中的复选框,我会显示一个对应于复选框选择的 div(即,如果我选择 Test CheckBox Two,则会显示一个对应于该复选框的 div)。

单击复选框时,我可以毫无问题地隐藏和显示 div。我遇到的问题是,在此过程中的某个时刻,用户打开了一个模态屏幕,当它关闭时,页面会进行回发/重新加载。然后,无论选中哪些复选框,都会隐藏 div。

我假设这是因为我在复选框的单击事件上调用了该函数。我需要在打开的模式关闭时选择显示的相同 div,而无需重新单击复选框。

我的html:

 <input type="checkbox" runat="server" id="cbImplement" class="selectCriteria" title="Implementation" value="cbImplement" /><span style="font-weight: bold; color: #4b6c9e">Implement</span>

<ul id="ulTabs">
    <li class="displayItem" id="liImplement" style="display: none"><a href="#divImplement">
        <span style="font-weight: bold; color: #4b6c9e;">Implement</span></a></li>
</ul>

<div id="divImplement" class="divframe"></div>

我的 jquery:

     $(".selectCriteria").click(function () {
         var id = $(this).attr('id'); // get checkbox id

       if ($(this).is(':checked')) {
        // Show Implementation
           if (checkboxID == "cbImplement") {
               $('#liImplement').show();
               $('#divImplement').show();
        }
    }
    else{
        // Hide Implementation
        if (checkboxID == "cbImplement") {
            $('#liImplement').hide();
            $('#divImplement').hide();
        }
    }
 });

【问题讨论】:

    标签: jquery html postback show


    【解决方案1】:

    只需将页面设置为每次加载页面时执行一个函数,并显示 div。这样,当页面第一次加载时,复选框被取消选中并且 div 被隐藏。在模态屏幕关闭后重新加载页面时,函数会再次执行并显示隐藏的 div。

    【讨论】:

      猜你喜欢
      • 2018-07-29
      • 2022-01-15
      • 2020-06-06
      • 1970-01-01
      • 2021-10-07
      • 1970-01-01
      • 2017-09-23
      • 2017-02-05
      相关资源
      最近更新 更多