微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

jquery – 如何在一个bootstrap模式中绑定动态数据

我的形式有一个模态
<div class="modal fade" id="myModal" 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-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel">Image Tag Description</h4>
      </div>
      <div class="modal-body">
          <p id="desc">
        Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,when an unkNown printer took a galley of type and scrambled it to make a type specimen book.
      </p>
          <h2 id="cost">Cost : 20$</h2>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-default" data-dismiss="modal">Edit</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div>
  </div>
</div>

我有多个toggel莫代尔的按钮.
按钮的Html如下

<button class="btn btn-primary tag_cnt" data-trigger="hover" 
        data-target="#myModal" data-toggle="modal" type="button" 
        style="top:144px; left:510px" value="1"></button>

我的表格中有多个按钮.现在我必须在每个按钮单击中调用相同的模态,我想在模态中动态显示数据.什么是解决方案?

解决方法

您可以将动态变量传递给函数,然后在函数中使用该变量来“手动”打开模态:
<button class="btn btn-primary tag_cnt" style="top:144px; left:510px" onclick="showModal('data')" type="button" value="1"></button>

在您的JavaScript中,您可以像这样访问:

function showModal(data)
{
   //you can do anything with data,or pass more data to this function. i set this data to modal header for example
   $("#myModal .modal-title").html(data)
   $("#myModal").modal();
}

原文地址:https://www.jb51.cc/jquery/178572.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐