gpt4 book ai didi

javascript - 根据日期比较更改innerHTML

转载 作者:行者123 更新时间:2023-12-03 09:36:15 25 4
gpt4 key购买 nike

我目前显示以下代码:

<h1  id="header1" class="loginhead">Welcome to the <%=formFields.getDisplayValue("programName")%> Registration Site, .</h1> 

我需要将其替换为:

<h1  id="header2" class="loginhead" >The <%=formFields.getDisplayValue("programName")%> Registration Site, is now closed.</h1> 

我需要在日期和时间为 7/15/15 11:59PM PT 时进行替换

有什么方法可以使用JqueryJSPJavascript来做到这一点吗?

更新**

    <h1  id="header" class="loginhead" ><span id='welcome'></span><span id='welcome2'></span> <%=formFields.getDisplayValue("programName")%> Registration Site <span id='closed'></span> </h1> 
<script>
var now = new Date().getTime(); //Return the number of milliseconds since 1970/01/01:

var epochTimeJul15_1159pm = 1437019199000; // number of milliseconds since 1970/01/01 at Jul 15_11:59:59pm. See http://www.epochconverter.com/.

var timeTillChange = epochTimeJul15_1159pm - now;

function changeHeader(){
document.getElementById('closed').innerHTML = ' is now closed.'; //change the html/text inside of the span with the id closed'.
}

function changeHeader1()
{
if(epochTimeJul15_1159pm <= now)
{
document.getElementById('welcome').innerHTML = 'The ';
}
}

function changeHeader2()
{
if(now < epochTimeJul15_1159pm)
{
document.getElementById('welcome2').innerHTML = 'Welcome to the ';
}
}
setTimeout(changeHeader, timeTillChange); //will wait to call changeHeader function until timeTillChange milliseconds have occured.
setTimeout(changeHeader1, timeTillChange);
setTimeout(changeHeader2, timeTillChange);
</script>

最佳答案

首先让使用 javascript 更容易编辑 html。我们将通过创建一个空范围来将关闭的消息插入到以下位置来完成此操作:

<h1  id="header" class="loginhead" >Welcome to the <%=formFields.getDisplayValue("programName")%> Registration Site <span id='closed'></span> </h1> 

现在在你的 javascript 部分:

var now = new Date().getTime(); //Return the number of milliseconds since 1970/01/01:

var epochTimeJul15_1159pm = 1437019199000; // number of milliseconds since 1970/01/01 at Jul 15_11:59:59pm. See http://www.epochconverter.com/.

var timeTillChange = epochTimeJul15_1159pm - now;

function changeHeader(){
document.getElementById('closed').innerHTML = ' is now closed.'; //change the html/text inside of the span with the id closed'.
}

setTimeout(changeHeader, timeTillChange); //will wait to call changeHeader function until timeTillChange milliseconds have occured.

这将使标题在时钟到达 11:59:59 时立即得到编辑。

关于javascript - 根据日期比较更改innerHTML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31326481/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com