【发布时间】:2019-10-03 17:14:20
【问题描述】:
我有一个如下所示的 html/php 代码,属于以下屏幕截图,其中当我们选择 下拉列表 和 input-box 时>一周的开始日期、开始时间、一周的结束日期和结束时间。
当我们选择一周的同一天(Start Day of Week 和 End Day of Week)时,现在在下面的屏幕截图中,然后 结束时间应始终大于开始时间。此时,结束时间小于开始时间,这在技术上是不正确的。
<form>
<div style="text-align:right;margin-right:9px;">
<button type="submit" onclick="check()">Save</button>
</div>
<div class="start-time+end-time" style="display:flex; text-align: center">
<div class="start-time" style="display:inline-flex;align-items:center;justify-content:center;">
<p>Start Day of Week</p>
<select id="startDay" name="select_start_day" style="margin-left: 10px;">
<option value="mon" name="select_start_day" <?php if($data->{"select_start_day"}==mon){echo 'selected';}?>>Monday</option>
<option value="tue" name="select_start_day" <?php if($data->{"select_start_day"}==tue){echo 'selected';}?>>Tuesday</option>
<option value="wed" name="select_start_day" <?php if($data->{"select_start_day"}==wed){echo 'selected';}?>>Wednesday</option>
<option value="thu" name="select_start_day" <?php if($data->{"select_start_day"}==thu){echo 'selected';}?>>Thursday</option>
<option value="fri" name="select_start_day" <?php if($data->{"select_start_day"}==fri){echo 'selected';}?>>Friday</option>
<option value="sat" name="select_start_day" <?php if($data->{"select_start_day"}==sat){echo 'selected';}?>>Saturday</option>
<option value="sun" name="select_start_day" <?php if($data->{"select_start_day"}==sun){echo 'selected';}?>>Sunday</option>
</select>
<p style="margin-left:12px;margin-right:10px;">time(hhmm) </p>
<input type="text" name="start_time" style="width: 12%;height: 22px;" value="<?php if($data->{"start_time"}<>''){echo $data->{"start_time"};} ?>">
</div>
<div class="end-time" style="display:inline-flex;align-items:center;justify-content:center;">
<p>End Day of Week</p>
<select id="endDay" name="select_end_day" style="margin-left: 10px;">
<option value="mon" name="select_end_day" <?php if($data->{"select_end_day"}==mon){echo 'selected';}?>>Monday</option>
<option value="tue" name="select_end_day" <?php if($data->{"select_end_day"}==tue){echo 'selected';}?>>Tuesday</option>
<option value="wed" name="select_end_day" <?php if($data->{"select_end_day"}==wed){echo 'selected';}?>>Wednesday</option>
<option value="thu" name="select_end_day" <?php if($data->{"select_end_day"}==thu){echo 'selected';}?>>Thursday</option>
<option value="fri" name="select_end_day" <?php if($data->{"select_end_day"}==fri){echo 'selected';}?>>Friday</option>
<option value="sat" name="select_end_day" <?php if($data->{"select_end_day"}==sat){echo 'selected';}?>>Saturday</option>
<option value="sun" name="select_end_day" <?php if($data->{"select_end_day"}==sun){echo 'selected';}?>>Sunday</option>
</select>
<p style="margin-left:12px;margin-right:10px;">time(hhmm) </p>
<input type="text" name="end_time" style="width: 12%;height: 22px;" value="<?php if($data->{"end_time"}<>''){echo $data->{"end_time"};} ?>">
</div>
</div>
</form>
问题陈述:
我想知道当星期几相同然后结束时间应该总是大于JavaScript代码strong>开始时间。如果它不是表单不应该保存并且它 应该抛出一个错误或警告。
上面的 html/php 代码在 form 标签内,顶部有 save button。
这是我尝试过的:
function check() {
if((document.getElementById("startDay").value = "monday") && (document.getElementById("endDay").value = "monday")) {
}
else if((document.getElementById("startDay").value = "tuesday") && (document.getElementById("endDay").value = "tuesday")) {
}
else if((document.getElementById("startDay").value = "wednesday") && (document.getElementById("endDay").value = "wednesday")) {
}
else if((document.getElementById("startDay").value = "thursday") && (document.getElementById("endDay").value = "thursday")) {
}
else if((document.getElementById("startDay").value = "friday") && (document.getElementById("endDay").value = "friday")) {
}
else if((document.getElementById("startDay").value = "saturday") && (document.getElementById("endDay").value = "saturday")) {
}
else if((document.getElementById("startDay").value = "sunday") && (document.getElementById("endDay").value = "sunday")) {
}
}
【问题讨论】:
-
有许多不同的方法。你试过什么?
-
@Moob 这就是我尝试过的。如果我想出更多逻辑,我会更新更多。
-
@Moob 我们还必须验证输入字段。让我知道它是否有意义。
标签: javascript jquery html forms validation