如何将 id 复选框添加到模态框?

2022-01-17 00:00:00 modal-dialog jquery php

可能重复:
如何将复选框 id 传递给模态框?

我有一个表格,每行都有一个复选框和一个按钮.每当按下按钮时,都会出现一个模态框,同时复选框也会被选中.

I have a table which each row have a checkbox and a button. whenever the button is pressed, a modal box will appear and at the same time the checkbox will get checked as well.

模式框会询问用户是否要删除特定记录.如果是,表格将被提交.如果否,复选框将被取消选中.

The modal box will as ask user if want to delete particular record. If Yes, the form will be submitted. If No, the checkbox will be unchecked.

我遇到了取消选中复选框的问题.任何人都可以帮助提供示例代码吗?如何将复选框 id 传递给模态框,以便取消选中该特定复选框?

I am facing issue with getting the checkbox unchecked. Anyone can assist with sample code? How do I pass the checkbox id to the modal box so that that particular checkbox can be unchecked?

谢谢.

     var buttons3 = $("#yns button").click(function(e) { 
    // get user input
     var yes = buttons3.index(this) === 0;
     if (yes){
     $('form#form1').submit();
     return true;
     } 
    else{
     //How to get the particular Checkbox id so that it can be unchecked? 

  $(this).dialog("close");

 return false;

 } 

});

我的模态框 Html:

My Modal Box Html:

<div class="widget modal2" id="yns"> <header>
 <h2>Confirmation</h2></header> <section>
   <p> Do you want to delete this item? </p> <!-- yes/no buttons --> <p> 
<button class="button" type="button">Yes</button> 
<button class="button" type="button">No</button> 
</p> </section> </div> 

我的表格 HTML:

<tr>                                        
   <td><input type="checkbox" id="measure<?php echo $count;?>
    " name="measureid[]" value="<?php echo $items>"></td>
    <td><?php  echo $Name;?></td>
    <td>
  <ul id="tip" class="abuttons">
    <li><a class="button"><span class="edit" title="Edit"></span></a></li>
    <li><a rel="#yns" id="unitbtn<?php echo $count;?>" class="modalInput button">
       <span class="delete" title="Delete"></span></a></li>
  </ul>
  </td>
 </tr>

Modal 和 Table 在同一个 php 页面中.

Modal and Table within same php page.

推荐答案

你的问题我不清楚,所以我假设(不是一个很好的问题)一次只选中一个复选框,所以你可以取消选中它

your question not clear to me, so i have assumed (not a very good one) that only one checkbox is checked at a moment so you can uncheck it by

$("input[name='measureid\[\]']:checked").removeAttr("checked")

它将取消选中已选中并具有 name="measureid[]" 的复选框

it will uncheck the checkbox that is checked and has name="measureid[]"

相关文章