1
<tr>
<td>Knowledge</td>
<td><input type="text" name="Knowledge" style="height: 30px; width: 220px;" class="computethis" id="knowledge" Placeholder = "Enter Grade" autocomplete ="off" /></td>
</tr>
<tr>
<td>Understanding</td>
<td><input type="text" name="understanding" style="height: 30px; width: 220px;" class="computethis" id="understanding" Placeholder = "Enter Grade" autocomplete ="off" /></td>
</tr>
<tr>
<td>Process or Skills</td>
<td><input type="text" name="process" style="height: 30px; width: 220px;" class="computethis" id="process" Placeholder = "Enter Grade" autocomplete ="off" /></td>
</tr>
<tr>
<td>Performance or Products</td>
<td><input type="text" name="performance" style="height: 30px; width: 220px;" class="computethis" id="products" Placeholder = "Enter Grade" autocomplete ="off" /></td>
</tr>
<tr>
<td>Grade Total </td>
<td><input type="textbox" name="grade" style="height: 30px; width: 220px;" id="totalgrade" Placeholder = "Average Total" autocomplete ="off" readonly="readonly"></td>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td colspan='2'><button class="btn btn-info" style="40px" id="save_button" Onclick="insert();"><i class="fa fa-floppy-o"> Save Grade</i></button><span class="alert alert-success" id="loading"></span></td>
</tr>
我只是每個文本框都只有25%我想計算每個文本字段中的特定百分比並計算總分數
<script>
// computation of average
jQuery(".computethis").keyup(function(){
var sum = 0;
var avg = 0;
jQuery('.computethis').each(function() {
sum += Number(jQuery(this).val());
});
var $allx = jQuery(':text.computethis');
var $emptyx = $allx.filter('[value=""]');
var num = $allx.length - $emptyx.length ;
if(num > 0) { avg = Number(sum/num); }
// jQuery('#prj_usgtot').val(sum);
jQuery('#totalgrade').val(avg.toPrecision(2));
});
</script>
我怎樣才能讓每一個textfield
具體百分比,它的onkeyup應自動計算平均獲得總成績。
我已經不容許在輸入文本的其他字符或特殊字符驗證,這裏是我的公式,希望它會清除掉你,totalgrade =知識(價值* .15)+理解(價值* .25)+產品(價值* .25)+過程(價值* .25)/ 4,謝謝ans,這也有助於我的其他問題並對我的英語語法感到抱歉 – user3156227