所以我有一个表格,它显示了每行的日期和其他重要细节的列表。我想要做的是验证表中的日期是否与当前日期(当前日期)匹配,如果匹配,它将自动禁用输入日期元素。这是我的代码
<table>
<tr>
<td><input type="text" class="form-control" name="date'.$counter.'" id="date'.$counter.'"></td>
<td><input type="text" class="form-control" name="timein'.$counter.'" id="timein'.$counter.'"></td>
<td><input type="text" class="form-control" name="timeout'.$counter.'" id="timeout'.$counter.'"></td>
<tr>
</table>
这是我的 JS 代码:
//This will get the current date
var curDate = new Date();
var dd = String(curDate.getDate()).padStart(2, '0');
var mm = String(curDate.getMonth() + 1).padStart(2, '0'); //January is 0!
var yyyy = curDate.getFullYear();
curDate = yyyy + '-' + mm + '-' + dd;
//This will get the current date
for(i = 1; i <=100; i++){
var dateApplied = $('#dateApplied' + i).val();
if (dateApplied = curDate){
$('#dateApplied' + i).disabled = true;
$('#timein' + i).disabled = true;
$('#timeout' + i).disabled = true;
}
}
//This will get the current date
var curDate = new Date();
var dd = String(curDate.getDate()).padStart(2, '0');
var mm = String(curDate.getMonth() + 1).padStart(2, '0'); //January is 0!
var yyyy = curDate.getFullYear();
curDate = yyyy + '-' + mm + '-' + dd;
//This will get the current date
for(i = 1; i <=100; i++){
var dateApplied = $('#date' + i).val();
if (dateApplied == curDate){
$('#date' + i).attr('disabled','disabled');
}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table>
<tr>
<td><input type="text" class="form-control" name="" id="date1" value="2019-04-05"></td>
<td><input type="text" class="form-control" name="" id="timein1"></td>
<td><input type="text" class="form-control" name="" id="timeout1"></td>
</tr>
<tr>
<td><input type="text" class="form-control" name="" id="date2" value="2019-04-06"></td>
<td><input type="text" class="form-control" name="" id="timein2"></td>
<td><input type="text" class="form-control" name="" id="timeout2"></td>
</tr>
</table>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句