0
您好自動影響我有表具有5列變化在總
Name Salary Bonus Deduction Total
Ahmed 500 500 100 900
計算總的是根據我的代碼 Total=Salary+Bonus-Deduction
和在紅色總 我實際上需要什麼,如果我改變工資單元或獎金單元格或扣除單元格影響總單元格 假設我添加了上面的行然後編輯工資 從500到2000意味着在此時間行將如下 Ahmed 2000 500 100 2400 總數將是240 0與綠色 如何通過改變總
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
<script src="~/Scripts/jquery-1.10.2.js"></script>
<script>
$(function() {
$("#btn").click(function() {
var x = $("#txt1").val();
var y = $("#txt2").val();
var z = $("#txt3").val();
var M = $("#txt4").val();
var L = parseInt(y) + parseInt(z) - parseInt(M);
$("#tb").append("<tr> <td>" + x + "</td> <td>" + y + "</td> <td>" + z + "<td>" + M + "</td><td>" + L + "</td></tr>");
$("#tb tr").each(function() {
var total = $(this).find("td:nth-child(5)").html();
if(parseInt(total)>1000)
{
$(this).find("td:nth-child(5)").css("background-color", "green");
}
if (parseInt(total) < 1000) {
$(this).find("td:nth-child(5)").css("background-color", "red");
}
if (parseInt(total) == 1000) {
$(this).find("td:nth-child(5)").css("background-color", "yellow");
}
});
});
$("#tb").on("click", "tr", function() {
$(this).find("td").slice(0, 4).prop("contenteditable", true);
});
});
</script>
<style>
.red{
color:#ff0000;
font-weight:bold;
}
</style>
</head>
<body>
<div>
Name<input type="text" id="txt1" /><br />
Salary<input type="text" id="txt2" /><br />
Bonus<input type="text" id="txt3" /><br />
Deduction<input type="text" id="txt4" /><br />
<input type="button" value="add" id="btn" />
<table>
<thead>
<tr>
<td>
Name
</td>
<td>
Salary
</td>
<td>
Bonus
</td>
<td>
Deduction
</td>
<td>
total
</td>
</tr>
</thead>
<tbody id="tb" class="tb1"></tbody>
</table>
</div>
</body>
</html>
非常感謝它解決 – user3223372