我的 Switch 语句只执行第一种情况。我在适当的部分包含了休息时间,但它似乎不起作用。
我正在尝试获取当前日期并将该日期与表单日期进行比较,如果它在当前日期之前删除该表单选项。我已经能够使用简单的 if else 语句成功地完成此操作,但我认为 switch 语句会更快。
感谢所有帮助。
JS
var checkapril1 = new Date();
checkapril1.setFullYear(2013, 3, 3);
var checkapril2 = new Date();
checkapril2.setFullYear(2013, 3, 17);
var checkmay1 = new Date();
checkmay1.setFullYear(2013, 4, 1);
var checkmay2 = new Date();
checkmay2.setFullYear(2013, 4, 15);
var checkmay3 = new Date();
checkmay3.setFullYear(2013, 4, 29);
var checkjune1 = new Date();
checkjune1.setFullYear(2013, 5, 12);
var checkjune2 = new Date();
checkjune2.setFullYear(2013, 5, 26);
var todaydate = new Date();
var e = document.getElementById("EventDate");
switch (true) {
case checkapril1 < todaydate:
for (var i = 0; i < e.length; i++)
var things = e.options[1];
things.style.display = "none";
things.disabled = true;
break;
case checkapril2 < todaydate:
for (var i = 0; i < e.length; i++)
var things = e.options[2];
things.style.display = "none";
things.disabled = true;
break;
case checkmay1 < todaydate:
for (var i = 0; i < e.length; i++)
var things = e.options[3];
things.style.display = "none";
things.disabled = true;
break;
case checkmay2 < todaydate:
for (var i = 0; i < e.length; i++)
var things = e.options[4];
things.style.display = "none";
things.disabled = true;
break;
case checkmay3 < todaydate:
for (var i = 0; i < e.length; i++)
var things = e.options[5];
things.style.display = "none";
things.disabled = true;
break;
case checkjune1 < todaydate:
for (var i = 0; i < e.length; i++)
var things = e.options[6];
things.style.display = "none";
things.disabled = true;
break;
case checkjune2 < todaydate:
for (var i = 0; i < e.length; i++)
var things = e.options[7];
things.style.display = "none";
things.disabled = true;
break;
}
HTML
<form class="lpeRegForm formNotEmpty" method="post" enctype="application/x-www-form- urlencoded" action="http://info.kinnser.com/index.php/leadCapture/save" id="mktForm_145" name="mktForm_145">
<ul class='mktLblLeft'>
<li class='mktFormReq mktField'>
<label>EVENT DATE:</label><span class='mktInput'><select class='mktFormSelect mktFReq' name="EventDate" id="EventDate" size='1' tabIndex='1'><option value='' selected='selected'>Please Select...</option><option value='April 3 2013'>April 3 2013</option><option value='April 17'>April 17 2013</option><option value='May 1'>May 1 2013</option><option value='May 15'>May 15 2013</option><option value='May 29'>May 29 2013</option><option value='June 12'>June 12 2013</option><option value='June 26'>June 26 2013</option></select><span class='mktFormMsg'></span></span>
</li>
<li class='mktFormReq mktField'>
<label>First Name:</label><span class='mktInput'><input class='mktFormText mktFormString mktFReq' name="FirstName" id="FirstName" type='text' value="" maxlength='255' tabIndex='2' /><span class='mktFormMsg'></span></span>
</li>
<li class='mktFormReq mktField'>
<label>Last Name:</label><span class='mktInput'><input class='mktFormText mktFormString mktFReq' name="LastName" id="LastName" type='text' value="" maxlength='255' tabIndex='3' /><span class='mktFormMsg'></span></span>
</li>
<li class='mktFormReq mktField'>
<label>Agency Name:</label><span class='mktInput'><input class='mktFormText mktFormString mktFReq' name="Company" id="Company" type='text' value="" maxlength='255' tabIndex='4' /><span class='mktFormMsg'></span></span>
</li>
<li class='mktFormReq mktField'>
<label>Email Address:</label><span class='mktInput'><input class='mktFormText mktFormEmail mktFReq' name="Email" id="Email" type='text' value="" maxlength='255' tabIndex='5' /><span class='mktFormMsg'></span></span>
</li>
<li class='mktFormReq mktField'>
<label>Zip Code:</label><span class='mktInput'><input class='mktFormText mktFormString mktFReq' name="PostalCode" id="PostalCode" type='text' value="" maxlength='255' tabIndex='6' /><span class='mktFormMsg'></span></span>
</li>
<li class='mktFormReq mktField'>
<label>Phone Number:</label><span class='mktInput'><input class='mktFormText mktFormPhone mktFReq' name="Phone" id="Phone" type='text' value="" maxlength='255' tabIndex='7' /><span class='mktFormMsg'></span></span>
</li>
<li class='mktFormReq mktField'>
<label>Role:</label><span class='mktInput'><select class='mktFormSelect mktFReq' name="Role__c" id="Role__c" size='1' tabIndex='8'><option value='' selected='selected'>Please Select...</option><option value='Administrator'>Administrator</option><option value='Billing'>Billing</option><option value='CEO'>CEO</option><option value='CFO'>CFO</option><option value='Clinician'>Clinician</option><option value='Consultant'>Consultant</option><option value='D.O.N.'>D.O.N.</option><option value='Director of Operations (DOO)'>Director of Operations (DOO)</option><option value='I.T.'>I.T.</option><option value='Other'>Other</option><option value='Owner'>Owner</option><option value='Q.A.'>Q.A.</option><option value='Therapist'>Therapist</option></select><span class='mktFormMsg'></span></span>
</li>
<li class='mktFormReq mktField'>
<label>Medicare Census:</label><span class='mktInput'><select class='mktFormSelect mktFReq' name="Agency_Census_Range__c_account" id="Agency_Census_Range__c_account" size='1' tabIndex='9'><option value='' selected='selected'>Please Select...</option><option value='0 - 50'>0 - 50</option><option value='51 - 125'>51 - 125</option><option value='126 - 250'>126 - 250</option><option value='251 - 500'>251 - 500</option><option value='501-750'>501-750</option><option value='751-1000'>751-1000</option><option value='1001+'>1001+</option></select><span class='mktFormMsg'></span></span>
</li>
<li class='mktField' style="display: none;">
<label>Lead Source:</label><span class='mktInput'><input class='mktFormHidden' name="LeadSource" id="LeadSource" type='hidden' value="Product Tour" /><span class='mktFormMsg'></span></span>
</li>
<li class='mktField' style="display: none;">
<label>Referral Code:</label><span class='mktInput'><input class='mktFormHidden' name="Event_Ref_Source__c" id="Event_Ref_Source__c" type='hidden' value="Product Tour" /><span class='mktFormMsg'></span></span>
</li>
<li class='mktField' style="display: none;">
<label>OfferID:</label><span class='mktInput'><input class='mktFormHidden' name="OfferID" id="OfferID" type='hidden' value="" /><span class='mktFormMsg'></span></span>
</li>
<li class='mktField mktLblRight'><span class='mktInput mktLblRight'><input class='mktFormCheckbox' name="SalesMeetingRequest" id="SalesMeetingRequest" type='checkbox' value="1" tabIndex='13' /><label>Yes, I want to speak to a Kinnser Software solutions expert.</label> <span class='mktFormMsg'></span></span>
</li>
<li id='mktFrmButtons'>
<label> </label>
<input id='mktFrmSubmit' type='submit' style="width: auto; overflow: visible; padding-left: .25em; padding-right: .25em;" value='Register Now' name='submitButton' onclick='formSubmit(document.getElementById("mktForm_145")); return false;' />
<input style='display: none;' id='mktFrmReset' type='reset' value='Clear' name='resetButton' onclick='formReset(document.getElementById("mktForm_145")); return false;' />
</li>
</ul> <span style="display:none;"><input type="text" name="_marketo_comments" value="" /></span>
<input type="hidden" name="lpId" value="1811" />
<input type="hidden" name="subId" value="26" />
<input type="hidden" name="munchkinId" value="010-FKU-440" />
<input type="hidden" name="kw" value="" />
<input type="hidden" name="cr" value="" />
<input type="hidden" name="searchstr" value="" />
<input type="hidden" name="lpurl" value="http://info.kinnser.com/2013ProductTour.html?cr={creative}&kw={keyword}" />
<input type="hidden" name="formid" value="145" />
<input type="hidden" name="returnURL" value="http://info.kinnser.com/2013ProductTourThanks.html" />
<input type="hidden" name="retURL" value="http://info.kinnser.com/2013ProductTourThanks.html" />
<input type="hidden" name="returnLPId" value="1812" />
<input type="hidden" name="_mkt_disp" value="return" />
<input type="hidden" name="_mkt_trk" value="id:010-FKU-440&token:_mch-kinnser.com-1363892390400-55419" />
</form>