【问题标题】:How to hide a div until a certain date如何在某个日期之前隐藏 div
【发布时间】:2012-09-09 21:09:13
【问题描述】:

我有一个 div 需要隐藏到 10 月 12 日,然后从 10 月 13 日开始显示。该站点是用 C# .NET 构建的,因此我可以在 HTML 页面的代码隐藏中添加一个 if 语句。不确定这是否可行,或者我是否需要一个 jQuery 解决方案(我对此一无所知)。任何帮助将不胜感激。

这是 HTML 中的代码:

<p style="bold">SHOW THROUGH 10/12!!!<p>
<p>Every day from now until Metastatic Breast Cancer Awareness Day (Oct. 13), a new video will be featured. Please check-in every day to hear a new story and come back on Oct. 13 to see the new, complete video wall.</p>

<div id="mbcRadioList">
    <p style="bold">BUILD BUT HIDE UNTIL 10/13!!!<p>
    <p><strong>Want to learn more?</strong> Select a video topic to better understand the varied experiences of people living with MBC and their family and friends.</p>
    <div class="checkBoxesColumn">
        <label><input name="videoWallRadio" type="radio" id="" value="" />View All</label>
        <label><input name="videoWallRadio" type="radio" id="" value="" checked />My MBC Journey</label>
        <label><input name="videoWallRadio" type="radio" id="" value="" />Challenges</label>
        <label><input name="videoWallRadio" type="radio" id="" value="" />Positive Outlooks &amp; Advice</label>
        <label><input name="videoWallRadio" type="radio" id="" value="" />Giving Thanks</label>
        <label><input name="videoWallRadio" type="radio" id="" value="" />Family / Friend Perspective</label>
    </div>
</div>

我在列表周围添加了&lt;div id="mbcRadioList"&gt; 以获得在代码隐藏中控制的句柄,如果有办法做到这一点。如果它是 jQuery 解决方案,我可以将其删除。

提前致谢!

【问题讨论】:

  • 我会尝试将 div 标记为隐藏,然后检查您的页面加载事件是否应该取消隐藏
  • 如果您在元素上添加了 id 和 runat="server",您可以在代码隐藏中引用它并根据您的条件将 Visible 设置为 false。
  • 我不建议这是客户端的事情。因为用户可以将他的系统日期更改为未来的任何日期
  • 不要忘记考虑时区。隐藏的 div 是否应该同时为所有用户显示,无论位置如何(午夜在某个任意位置)?还是应该出现在每个用户当地时间的午夜?
  • 使这成为客户端问题的另一个危险:时区。您必须在 GMT 时间完成所有数学运算。

标签: c# html date


【解决方案1】:

按照别人的建议去做:

1) 将 div 设置为runat="server"

2) 将 div 设置为visible="false"

3) 在Page_Load 的代码隐藏中,添加一个if 语句,该语句检查日期,然后将visible 更改为true

aspx 标记:

<div id="mbcRadioList" runat="server" visible="false">
    <p style="bold">BUILD BUT HIDE UNTIL 10/13!!!<p>
    <p><strong>Want to learn more?</strong> Select a video topic to better understand the varied experiences of people living with MBC and their family and friends.</p>
    <div class="checkBoxesColumn">
        <label><input name="videoWallRadio" type="radio" id="" value="" />View All</label>
        <label><input name="videoWallRadio" type="radio" id="" value="" checked />My MBC Journey</label>
        <label><input name="videoWallRadio" type="radio" id="" value="" />Challenges</label>
        <label><input name="videoWallRadio" type="radio" id="" value="" />Positive Outlooks &amp; Advice</label>
        <label><input name="videoWallRadio" type="radio" id="" value="" />Giving Thanks</label>
        <label><input name="videoWallRadio" type="radio" id="" value="" />Family / Friend Perspective</label>
    </div>
</div>

代码隐藏:

protected void Page_Load(object sender, EventArgs e)
    {
        // ..... your other code

                    if(DateTime.Now >= new DateTime(2012, 10, 13) ){
                          mbcRadioList.Visible = true;
                    }
    }

正如其他人所建议的,如果需要,请务必考虑时区。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-08-12
    • 1970-01-01
    • 2020-02-23
    • 2015-09-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多