[英]Javascript: Hide button on a specific date
I am creating a survey and I need the submit button to be hidden on a specific date. 我正在创建调查,并且需要在特定日期隐藏提交按钮。 In other words, I need the button to be hidden on 10/22/2013 only and for the button to be visible all other days.
换句话说,我只需要在2013年10月22日隐藏按钮,并在其他所有日子都可以看到该按钮。 I have been ripping my hair out figuring out why the code below does not work...am I missing something?...
我一直在梳理一下头发,弄清楚为什么下面的代码不起作用...我错过了什么吗?...
var x=new Date();
x.setFullYear(2013,9,22);
var today = new Date();
if (x=today)
{
document.getElementById('NextButton').style.visibility='hidden';
}
else if
{
document.getElementById('NextButton').style.visibility='visible';
}
You are assigning instead of validating: 您正在分配而不是验证:
var nextBtn = document.getElementById('NextButton'),
x = new Date(),
today = new Date();
x.setFullYear(2013,9,22);
if (x === today) {
nextBtn.style.visibility = 'hidden';
} else if {
nextBtn.style.visibility = 'visible';
}
Single =
assigns, whereas ==
or ===
compares equality. Single
=
分配,而==
或===
比较相等。
Side note: 边注:
===
is preferred (and therefore used above) because it verifies value and type. ===
是首选(因此在上面使用),因为它可以验证值和类型。 ==
verifies only value, ie 1 == '1'
because the values match despite one being an integer and one being a string, however 1 !== '1'
because while the value matches, the type does not. ==
仅验证值,即1 == '1'
因为尽管一个值是整数且一个是字符串,但值仍匹配,但是1 !== '1'
是因为值匹配时,类型却不匹配。 Just a little extra info. 只是一些额外的信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.