bootstrap怎么才能在点击链接时把那条记录的ID传给modal模态框?

发布时间: 2015/5/15 14:44:26

请问怎么才能在点击LINK时把那条记录的ID传给模态框呢?

链接

<a href="javascript:void(0);" class="jq_link" rel="<?php echo $val['id'];?>">link</a>

模态框

<div class="modal fade" id="Modal" 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">&times;</button>
        <h4 class="modal-title" id="myModalLabel jq_message">TITLE</h4>
      </div>
      <div class="modal-body">
        <form method="post" action="index.php&id=???这里需要传值" class="form-horizontal" role="form">
        <div class="form-group">
          <label for="inputname" class="col-sm-2 control-label">NAME</label>
          <div class="col-sm-8"><input type="text" name="name" id="inputname" value="" class="form-control"></div>
        </div>
        <div class="form-group">
          <label for="inputtel" class="col-sm-2 control-label">TEL</label>
          <div class="col-sm-8"><input type="text" name="tel" id="inputtel" value="" class="form-control"></div>
        </div>         
      </div>
      <div class="modal-footer">
        <button type="submit" class="btn btn-primary">SUBMIT</button>
      </div>
      </form>
    </div>
  </div>
</div>

JS

<script>
$(document).ready(function() {
  $(".jq_link").click(function() {
    var id = $(this).attr('rel');
    $("#Modal").modal();
  });
});
</script>


解决方法 1:

$(document).ready(function() {
  $(".jq_link").click(function() {
    var id = $(this).attr('rel');
    $("#Modal .modal-body > form").attr("action", "index.php?id=" + id);
    $("#Modal").modal();
  });
});


官方微信
官方QQ群
31647020