点击按钮,弹出模态框并加载数据

需求分析:在做修改数据的功能时,经常会有弹出模态框修改数据的需求,如图,点击编辑按钮,弹出模态框,并将该行的字段内容全部加载入模态框的相应标签中。

模态框

<div class="modal fade" id="myModal">
  <div class="modal-dialog">
    <form class="modal-content" method="get" id="studentForm" action="edit" role="form">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">
          <span aria-hidden="true">&times;</span><span class="sr-only">Close</span>
        </button>
        <h4 class="modal-title">请更改</h4>
      </div>
      <div class="modal-body">
        <table>
          <tr>
            <td><b>学号:</b></td>
            <td><input type="text" id="id" name="id" readonly></td>
          </tr>
          <tr>
            <td><b>姓名:</b></td>
            <td><input type="text" id="name" name="name"/></td>
          </tr>
          <tr>
            <td><b>登记时间:</b></td>
            <td><input type="text" id="time" name="time"/></td>
          </tr>
        </table>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
        <button type="submit" class="btn btn-primary">确定</button>
      </div>
    </form>
  </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

编辑按钮,弹出模态框并调用doEdit方法加载数据

<a id="edit_id" href="#" onclick="doEdit(this)" data-toggle="modal" data-target="#myModal" >

doEdit方法

function doEdit(obj) {//这个obj是编辑按钮的对象
      var tds = obj.parentNode.parentNode.childNodes;//当前对象的父节点的父节点的子节点数组
      document.getElementById("id").value=tds[1].innerText;
      document.getElementById("name").value=tds[2].innerText;
      document.getElementById("time").value=tds[3].innerText;
    }

  • 1
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值