[英]Hide record within a table when checkbox is checked
我試圖根據復選框的選中狀態隱藏/顯示表中的記錄
HTML
<label>Add Additional Once off</label>
<input type="checkbox" id="chkAdditionalOnceoff" onChange="display();"value="0"><br>
<label>Add Additional Monthly</label>
<input type="checkbox" id="chkAdditionalMonthly" onChange="display();"value="0">
<table>
<div id="AdditionalOnceoff" style="display:none">
<tr><td><input type="text" id="txtField1"></td>
<td><input type="text" id="txtField2"></td>
</tr>
</div>
<tr><td colspan="2">Normal Record to Display always</td></tr>
<div id="AdditionalMonthly" style="display:none">
<tr>
<td><input type="text" id="txtField3"></td>
<td><input type="text" id="txtField4"></td>
</tr>
</div>
</table>
JAVASCRIPT
function display(){
if (document.getElementById("chkAdditionalOnceoff").checked) {
document.getElementById("AdditionalOnceoff").style.display = "inline";
} else {
document.getElementById("AdditionalOnceoff").style.display = "none";
}
if (document.getElementById("chkAdditionalMonthly").checked) {
document.getElementById("AdditionalMonthly").style.display = "inline";
} else {
document.getElementById("AdditionalMonthly").style.display = "none";
}
}
因此,當復選框被選中時,包含記錄的相應<div>應該被隱藏/顯示
我發現該討論選中了復選框時隱藏了表中的其他行,但找不到我的方案的有效示例。
希望如此,您將在這里找到解決方案
$(document).ready(function(){ $('input[type="checkbox"]').click(function(){ var inputValue = $(this).attr("value"); $("." + inputValue).toggle(); }); });
.box{ color: #fff; padding: 20px; display: none; margin-top: 20px; } .red{ background: #ff0000; } .green{ background: #228B22; } .blue{ background: #0000ff; } label{ margin-right: 15px; }
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script> <label><input type="checkbox" name="colorCheckbox" value="red"> red</label> <label><input type="checkbox" name="colorCheckbox" value="green"> green</label> <label><input type="checkbox" name="colorCheckbox" value="blue"> blue</label> </div> <div class="red box">You have selected <strong>red checkbox</strong> so i am here</div> <div class="green box">You have selected <strong>green checkbox</strong> so i am here</div> <div class="blue box">You have selected <strong>blue checkbox</strong> so i am here</div>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.