我有 Drupal 生成的以下 HTML
<fieldset id="webform-component-lunchset" class="webform-component-fieldset form-wrapper" style="">
<div id="webform-component-lunchset--lunch" class="form-item webform-component webform-component-radios webform-container-inline" style="">
...Radio Button div tags here
</div>
</fieldset>
<fieldset id="webform-component-dinnerset" class="webform-component-fieldset form-wrapper" style="display: none;">
<div id="webform-component-dinnerset--dinner" class="form-item webform-component webform-component-radios webform-container-inline" style="display: none;">
...Radio Button div tags here
</div>
</fieldset>
我的意图是允许用户根据他开始预订时的一天中的时间来选择用餐时间。为此,我注意到我必须更改 style="display: none;" 对于我要隐藏的字段集,而 style="" 对于我要显示的字段集。我有以下 Javascript 语句来更改 DIV 标记的样式属性,但它似乎不起作用。任何帮助,将不胜感激。
window.onload = (function() {
var today = new Date();
var day = today.getDay();
var hour = today.getHours();
var lunchtime1 = document.getElementById('webform-component-lunchset');
var lunchtime2 = document.getElementById('webform-component-lunchset--lunch');
var dinnertime1 = document.getElementById('webform-component-dinnerset');
var dinnertime2 = document.getElementById('webform-component-dinnerset--dinner');
if (hour >= 15 && hour < 22) {
lunchtime1.style="display: none;";
lunchtime2.style="display: none;";
dinnertime1.style=" ";
dinnertime2.style=" ";
sundaytime1.style="display: none;";
}
});
不知道为什么它不起作用,将不胜感激任何帮助。先感谢您