我有html表,tr包含通过使用input type date and time
显示ng-repeat
字段的行。有些行来自数据库,有些行是我需要输入的用户。我有两个日期字段,如date1和date2,如果date2试图在未输入date1的情况下输入,则需要引发错误提示。并且还需要检查date1不应大于date2。我该怎么做,请帮助我
<table data-ng-model="Tbl" class="showtable">
<thead data-ng-model="Tblhead" data-ng-hide="True">
<tr>
<th><span>Date1</span></th>
<th><span>Date2</span></th>
<th><span>Time1</span></th>
<th><span>Time2</span></th>
</tr>
</thead>
<tbody>
<tr id="x" data-ng-repeat="customr in customrs">
<td ><input type="date" class="textbox" data-ng-model="customr.Date1" value="{{ customr.Date1}}" /></td>
<td><input type="date" class="textbox" data-ng-model="customr.Date2" value="{{ customr.Date2}}" onchange="checkTemplate()" /></td>
<td><input type="time" class="textbox" data-ng-model="customr.Time1" value="{{ customr.Time1}}" /></td>
<td><input type="time" class="textbox" data-ng-model="customr.Time2" value="{{ customr.Time2}}" /></td>
</tr></tbody>
</table>
脚本:
function checkTemplate() {
$("tr").each(function () {
var trIsEmpty = true;
var tr = $(this);
tr.find("td:not(.requirementRight)").each(function () {
td = $(this);
if (isEmpty(td) === false) {
trIsEmpty = false;
}
});
if (trIsEmpty == true) {
alert("");
}
});
function isEmpty(td) {
if (td.text == '' || td.text() == ' ') {
return true;
}
return false;
}
}