django bootstrap 向modal插件传递参数

20 篇文章 0 订阅
10 篇文章 0 订阅

1、modal 模态框 的代码如下:

<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
        <h4 class="modal-title" id="exampleModalLabel">New message</h4>
      </div>
      <div class="modal-body">
        <form>
          <div class="form-group">
            <label for="recipient-name" class="control-label">Title:</label>
            <input type="text" class="form-control" id="titletext">
          </div>
          <div class="form-group">
            <label for="message-text" class="control-label">Body:</label>
            <textarea class="form-control" id="bodytext"></textarea>
          </div>
        </form>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary" οnclick="edititem(this)">Save</button>
      </div>
    </div>
  </div>
</div>

在模态框中对两个input框加上了id


2、调用模态框的页面

<div class="table-responsive">
            <table class="table table-striped">
              <thead>
                <tr>
                  <th>title</th>
                  <th>body</th>
                  <th>time</th>
                  <th>operation</th>
                </tr>
              </thead>
              <tbody>
                {% for emp in pagination.objs %}
                <tr>
                <td id="title">{{ emp.title }}</td>
                <td id="body">{{ emp.body }}</td>
                <td id="time">{{ emp.timestamp }}</td>
                <td>
                        <button type="button" class="btn btn-default btn-xs" οnclick="edititem(this)">
                        <span class="glyphicon glyphicon-edit" aria-hidden="true"><span>
                        </button>
                        <button type="button" class="btn btn-default btn-xs" οnclick="getrmitem(this)">
                        <span class="glyphicon glyphicon-remove" aria-hidden="true"><span>
                        </button>
                </td>
                </tr>
                {% endfor %}
             </tbody>
          </table>
</div>

效果如下:

当我点击编辑图标时,将这一行的数据传给模态框的input中


3、js实现向模态框modal传递数据

function edititem(obj){
var tr=$(obj).parent().parent();
var title = tr.children("td#title").text();
var body = tr.children("td#body").text();
$('#titletext').val(title);
$('#bodytext').val(body);
$('#exampleModal').modal('show')

};

4、结果如下


  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值