如何检查具有输入类型日期和时间的用户输入字段的html表tr td行是否为空

时间:2019-01-23 12:48:36

标签: jquery html

我有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;
}

}

0 个答案:

没有答案