我使用JavaScript开发了网页。有两个复选框选中并删除错误。然后两个tr在显示,当我没有选中复选框。我如何解决这个问题?在图像Style =“display = none;”在我的项目中无法正常工作
有选择2盒,取出,但显示器3的图像,然后选择3复选框,删除然后再次隐藏TR提起,但我想隐藏,当我删除选定的字段。
第二图象必须是这样的
,但矿,
var arr = [];
var selectedVal = 0;
$("input[name='invoiceTotal']").change(function() {
selectedVal = this.value;
var granTotal = 5000;
if (this.checked) {
arr.push(this.value);
} else {
//alert(selectedVal);
arr.splice(arr.indexOf(this.value), 1);
hidenSelected(selectedVal);
}
var sum = arr.reduce((a, b) => parseFloat(a) + parseFloat(b), 0);
console.log("granTotal : " + granTotal);
console.log(sum);
console.log("sum : " + sum);
console.log("selectedVal : " + selectedVal);
if (sum == 0) {
hidenUpload();
} else if (sum <= granTotal) {
chowSelected(selectedVal);
} else {}
});
function chowSelected(j) {
document.getElementById(j).style.display = '';
}
function hidenSelected(j) {
alert(j);
document.getElementById(j).style.display = 'none';
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.2.3/jquery.min.js"></script>
<table border="1">
<tr style="display: ;">
<th>Month</th>
<th>Savings</th>
</tr>
<tr id="2771.0" style="display: none;">
<td>a</td>
<td>$100</td>
</tr>
<tr id="2826.0" style="display: none;">
<td>b</td>
<td>$200</td>
</tr>
<tr id="2087.5" style="display: none;">
<td>c</td>
<td>$300</td>
</tr>
<tr id="4314.0" style="display: none;">
<td>d</td>
<td>$400</td>
</tr>
<tr id="5000.0" style="display: none;">
<td>e</td>
<td>$500</td>
</tr>
</table>
<input type="checkbox" class="invot" name="invoiceTotal" value="2771.0">
<input type="checkbox" class="invot" name="invoiceTotal" value="2826.0">
<input type="checkbox" class="invot" name="invoiceTotal" value="2087.5">
<input type="checkbox" class="invot" name="invoiceTotal" value="4314.0">
<input type="checkbox" class="invot" name="invoiceTotal" value="5000.0">
请回答这个问题很快。
第二张图片不应该只显示“a”行吗?很难理解你在问什么。 –
@MattMokary我编辑代码请检查。 –
我是你的意思尊敬的表行打开和隐藏与输入框检查并取消选中 – prasanth