bootstrap modal 传值


请问怎么才能在点击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">×</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>

modal bootstrap

佐佐木小次狼 10 years, 6 months ago

JS


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

永远的清风 answered 10 years, 6 months ago

Your Answer