将行ID从页面的一个部分传递到另一个部分

时间:2014-12-03 14:27:57

标签: javascript php jquery html

我想通过以下方式将页面的一个部分的行ID传递给另一部分:enter image description here

用户将点击垃圾桶,将出现删除确认消息。以下代码显示了我如何从数据库中检索列表:

<?php while($row = mysql_fetch_array($query_set)) { ?>
<tr>

  <td><?php echo $row['cover_name'] ?></td>
  <td><?php echo 'R '.$row['sum_insured'] ?></td>
  <td><?php echo $row['info'] ?></td>
  <td>
      <a href="cover-type.php?id=<?php echo $row['coverid']?>"><i class="fa fa-pencil"></i></a>
      <a href="#myModal" onclick="<?php $coverid = $row['coverid'] ?>" role="button" data-toggle="modal"><i class="fa fa-trash-o"></i></a><!-- This is the link for the trash can to pass the id -->
  </td>
</tr>
<?php } ?>

点击以下<a href="#myModal" onclick="<?php $coverid = $row['coverid'] ?>" role="button" data-toggle="modal"><i class="fa fa-trash-o"></i></a><!-- This is the link for the trash can to pass the id -->

将出现以下流行音乐:

enter image description here 它有以下代码:

    <div class="modal small fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
            <h3 id="myModalLabel">Delete Confirmation</h3>
        </div>
        <div class="modal-body">
            <p class="error-text"><i class="fa fa-warning modal-icon"></i>Are you sure you want to delete the cover?<br>This cannot be undone.</p>
        </div>
        <div class="modal-footer">
            <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">Cancel</button>
            <a href="delete-cover.php?id=<?php echo $coverid ?>" class="btn btn-danger"  >Delete</a><!-- I would like to pass the id from that trash can button this the delete button -->
        </div>
      </div>
    </div>
</div>

我想将垃圾桶中的id链接到弹出的删除按钮。任何帮助将不胜感激

1 个答案:

答案 0 :(得分:0)

这肯定不好:

onclick="<?php $coverid = $row['coverid'] ?>"

应该是这样的:

onclick="jsfunctionname(<?php echo $row['coverid'];?>);"

或者,如果您在选择器上使用jQuery,则在链接中添加data-id="<?php echo $row['coverid'];?>",并获得$(this).data('id');