任何人都可以帮我解释如何计算员工出勤率,这是我的前端: [在此处输入图像说明] [1] 所有员工都是从数据库中列出的,我需要按月存储他们的出勤率。 用户只能在没有"的情况下,只要用户输入" no.of缺席日期"领域,"现在的天数"字段应更新no.of days present字段。我需要对这里列出的所有员工重复这一点。
Date.prototype.daysInThisMonthOfThisYear=function() {
return new Date(this.getFullYear(),this.getMonth()+1,0).getDate();
}
var days_inmonth = new Date().daysInThisMonthOfThisYear();
$(document).ready(function() {
$( "#absent_days" ).keyup(function() {
var days = $('#absent_days').val();
$( "#present_days" ).text( days_inmonth - days );
})
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<form class="empform" method="post" action="">
<table cellpadding="0" cellspacing="0" border="0" class="stdtable" id="emptable">
<colgroup>
<col class="con0" />
<col class="con1" />
<col class="con0" />
<col class="con1" />
<col class="con0" />
<col class="con1" />
</colgroup>
<thead>
<tr>
<th class="head0" style="width:5%">S.No</th>
<th class="head1" style="width:15%">First Name</th>
<th class="head0" style="width:15%">Last Name</th>
<th class="head1" style="width:15%">Department Name</th>
<th class="head0" style="width:20%">Mobile Number</th>
<th class="head1 no-sort" style="width:15%">No.of days present</th>
<th class="head0 no-sort" style="width:15%">No.of days absent</th>
</tr>
</thead>
<tfoot>
<tr>
<th class="head0">S.No</th>
<th class="head1">First Name</th>
<th class="head0">Last Name</th>
<th class="head1">Department Name</th>
<th class="head0">Mobile Number</th>
<th class="head1">No.of days present</th>
<th class="head0">No.of days absent</th>
</tr>
</tfoot>
<tbody>
<tr>
<td>1</td>
<td>Eric</td>
<td>Soft</td>
<td>IT Department</td>
<td>0123456789</td>
<td><div id="present_days"></div></td>
<td><div></div><input type="number" name="absent_days" id="absent_days" min="0" max="<?php echo date('t'); ?>" onChange="absentdays()" style="width:100%"></td>
</tr>
<tr>
<td>2</td>
<td>Eric</td>
<td>Soft</td>
<td>DB Department</td>
<td>0123456789</td>
<td><div id="present_days"></div></td>
<td><div></div><input type="number" name="absent_days" id="absent_days" min="0" max="<?php echo date('t'); ?>" onChange="absentdays()" style="width:100%"></td>
</tr>
<tr>
<td>3</td>
<td>Eric</td>
<td>Soft</td>
<td>DB Department</td>
<td>0123456789</td>
<td><div id="present_days"></div></td>
<td><div></div><input type="number" name="absent_days" id="absent_days" min="0" max="<?php echo date('t'); ?>" onChange="absentdays()" style="width:100%"></td>
</tr>
<tr>
<td>4</td>
<td>Eric</td>
<td>Soft</td>
<td>DB Department</td>
<td>0123456789</td>
<td><div id="present_days"></div></td>
<td><div></div><input type="number" name="absent_days" id="absent_days" min="0" max="<?php echo date('t'); ?>" onChange="absentdays()" style="width:100%"></td>
</tr>
</tbody>
</table>
<p class="stdformbutton">
<input type="submit" class="submit radius2" value="Submit">
<input type="reset" class="reset radius2" value="Reset" />
</p>
</form>
&#13;
答案 0 :(得分:0)
你在找这个:
我对你做了一些小改动:你不能拥有id="present_days"
和
单个HTML文档中多次id="absent_days"
次。 id
必须对每个DOM元素都是唯一的。所以我没有id
而是class
。
Date.prototype.daysInThisMonthOfThisYear=function() {
return new Date(this.getFullYear(),this.getMonth()+1,0).getDate();
}
var days_inmonth = new Date().daysInThisMonthOfThisYear();
$(document).ready(function() {
$( ".absent_days" ).change(function() {
var days = $(this).val();
$(this).closest("tr").find(".present_days" ).text( days_inmonth - days );
$(this).closest("tr").find(".hidden_present_days" ).val( days_inmonth - days );
})
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<form class="empform" method="post" action="">
<table cellpadding="0" cellspacing="0" border="0" class="stdtable" id="emptable">
<colgroup>
<col class="con0" />
<col class="con1" />
<col class="con0" />
<col class="con1" />
<col class="con0" />
<col class="con1" />
</colgroup>
<thead>
<tr>
<th class="head0" style="width:5%">S.No</th>
<th class="head1" style="width:15%">First Name</th>
<th class="head0" style="width:15%">Last Name</th>
<th class="head1" style="width:15%">Department Name</th>
<th class="head0" style="width:20%">Mobile Number</th>
<th class="head1 no-sort" style="width:15%">No.of days present</th>
<th class="head0 no-sort" style="width:15%">No.of days absent</th>
</tr>
</thead>
<tfoot>
<tr>
<th class="head0">S.No</th>
<th class="head1">First Name</th>
<th class="head0">Last Name</th>
<th class="head1">Department Name</th>
<th class="head0">Mobile Number</th>
<th class="head1">No.of days present</th>
<th class="head0">No.of days absent</th>
</tr>
</tfoot>
<tbody>
<tr>
<td>1</td>
<td>Eric</td>
<td>Soft</td>
<td>IT Department</td>
<td>0123456789</td>
<td><div class="present_days"></div><input type="hidden" class="hidden_present_days"/></td>
<td><div></div><input type="number" name="absent_days" class="absent_days" min="0" max="<?php echo date('t'); ?>" onChange="absentdays()" style="width:100%"></td>
</tr>
<tr>
<td>2</td>
<td>Eric</td>
<td>Soft</td>
<td>DB Department</td>
<td>0123456789</td>
<td><div class="present_days"></div><input type="hidden" class="hidden_present_days"/></td>
<td><div></div><input type="number" name="absent_days" class="absent_days" min="0" max="<?php echo date('t'); ?>" onChange="absentdays()" style="width:100%"></td>
</tr>
<tr>
<td>3</td>
<td>Eric</td>
<td>Soft</td>
<td>DB Department</td>
<td>0123456789</td>
<td><div class="present_days"></div><input type="hidden" class="hidden_present_days"/></td>
<td><div></div><input type="number" name="absent_days" class="absent_days" min="0" max="<?php echo date('t'); ?>" onChange="absentdays()" style="width:100%"></td>
</tr>
<tr>
<td>4</td>
<td>Eric</td>
<td>Soft</td>
<td>DB Department</td>
<td>0123456789</td>
<td><div class="present_days"></div><input type="hidden" class="hidden_present_days"/></td>
<td><div></div><input type="number" name="absent_days" class="absent_days" min="0" max="<?php echo date('t'); ?>" onChange="absentdays()" style="width:100%"></td>
</tr>
</tbody>
</table>
<p class="stdformbutton">
<input type="submit" class="submit radius2" value="Submit">
<input type="reset" class="reset radius2" value="Reset" />
</p>
</form>