简体   繁体   English

COLDFUSION:在表循环中为 td(row) 选择一个复选框

[英]COLDFUSION: select one checkbox for td(row) in a table loop

In the code below, I iterate through a table.在下面的代码中,我遍历了一个表。 There are two check-boxes for the desired row.所需行有两个复选框。 Once the first box is checked, I want to prevent the user from checking the other in that row.选中第一个框后,我想阻止用户选中该行中的另一个框。 If the user checks the second, s/he should be able to check other boxes (options).如果用户选中第二个,他/她应该能够选中其他框(选项)。

 <cfquery name="data" datasource="#dbMarks#"> SELECT helix_date, Helix_Title FROM Helix_Events </cfquery> <div class="container"> <div class="row"> <form action="save.cfm"> <div class="col-sm-12 col-md-8"> <h2>Select Helix Programme</h2> </div> <div class="col-sm-12 col-md-4 mtr mtop"> <select name="" id="" class="btn-markham"> <option value="">Semester 1</option> <option value="">Semester 2</option> </select> <button class="btn-markham" onclick="myFunction()"><span class="fa fa-print"></span>&nbsp;Print</button> <input type="submit" class="btn-markham2" value="Save"> <br></br> </div> <div class="col-md-12"> <table class="table"> <tr> <th>Date</th> <th>Event</th> <th class="mtc">Participation</th> <th class="mtc">Support</th> </tr> <cfoutput query="data" > <tr> <td>#dateformat(helix_date,"dd-mmm-yy")#</td> <td>#helix_title#</td> <td class="mtc"><input type="checkbox" name="check" value="1"> </td> <td class="mtc"><input type="checkbox" name="check2" value="2"></td> </tr> </cfoutput> </table> </div> </div> </form> </div> </div>

Please use this code line .请使用此代码行。 jQuery(this).closest('tr').find('[type=checkbox]').not(this).prop('disabled', true); which make the next checkbox disabled on check of current of checkbox.这使得在检查当前复选框时禁用下一个复选框。 Same way you can remove the disabled checkbox on uncheck using jQuery(this).closest('tr').find('[type=checkbox]').not(this).prop('disabled', false);同样的方式,您可以使用jQuery(this).closest('tr').find('[type=checkbox]').not(this).prop('disabled', false);在取消选中时删除禁用的复选框jQuery(this).closest('tr').find('[type=checkbox]').not(this).prop('disabled', false);

Please check below snippet for more understanding.请查看以下代码段以获取更多理解。

 $("input[type='checkbox']").on('change',function(){ if($(this).is(':checked')){ jQuery(this).closest('tr').find('[type=checkbox]').not(this).prop('disabled', true); }else{ jQuery(this).closest('tr').find('[type=checkbox]').not(this).prop('disabled', false); } });
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <cfquery name="data" datasource="#dbMarks#"> SELECT helix_date, Helix_Title FROM Helix_Events </cfquery> <div class="container"> <div class="row"> <form action="save.cfm"> <div class="col-sm-12 col-md-8"> <h2>Select Helix Programme</h2> </div> <div class="col-sm-12 col-md-4 mtr mtop"> <select name="" id="" class="btn-markham"> <option value="">Semester 1</option> <option value="">Semester 2</option> </select> <button class="btn-markham" onclick="myFunction()"><span class="fa fa-print"></span>&nbsp;Print</button> <input type="submit" class="btn-markham2" value="Save"> <br></br> </div> <div class="col-md-12"> <table class="table"> <tr> <th>Date</th> <th>Event</th> <th class="mtc">Participation</th> <th class="mtc">Support</th> </tr> <cfoutput query="data" > <tr> <td>#dateformat(helix_date,"dd-mmm-yy")#</td> <td>#helix_title#</td> <td class="mtc"><input type="checkbox" name="check" value="1"> </td> <td class="mtc"><input type="checkbox" name="check2" value="2"></td> </tr> </cfoutput> </table> </div> </div> </form> </div> </div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM