如何在模态中传递参数id?

时间:2018-06-02 08:08:50

标签: javascript jsp bootstrap-4 bootstrap-modal

我有一个表格,我想在模态中更新。问题是我无法在模态中获取参数id。我使用这个javascript,但我只是获得第一次点击的href attribut但不是第二次点击。

这是我的按钮

<a href="StaffController?action=UpdatePassword&staffid=<c:out value="${staff.staff_id}" />" class="btn btn-success btn-sm updatepassword" data-toggle="modal" data-target="#exampleModal">
                          <span data-feather="user-check"></span>
</a>    

这是我的javascript

<script>
    $('#exampleModal').on('shown.bs.modal', function () {
         var href = $('.updatepassword').attr('href');
         $('.fetched-data').val(href);
        })
</script>

这是我的模态

<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLabel">Set Password</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        <form method="POST" id ="update-password-form" action="StaffController">
          <div class="form-group">
          <input type="text" class="form-control fetched-data" id="staff_id" name="staff_id" value="<c:out value="${staff.staff_id}" />">
            <input type="password" name="staff_password" class="form-control" id="exampleInputPassword1" placeholder="Password">
          </div>
          <button type="submit" class="btn btn-secondary">Submit</button>
        </form>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
        <button type="submit" class="btn btn-primary" data-dismiss="modal">Save changes</button>
      </div>
    </div>
  </div>
</div>

0 个答案:

没有答案