如何以一种引导方式绑定动态数据 [英] How to bind dynamic data in one bootstrap modal
本文介绍了如何以一种引导方式绑定动态数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的表格中有一个模态
<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">×</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>
,我有多个切换模式的按钮. 按钮的HTML正在追踪
and i have multiple buttons which toggel modal. Html of button is following
<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>
我的表单中有多个按钮.现在,我必须在每次单击按钮时调用相同的模态,并且我想以模态动态显示数据.什么是解决方案?
i have multiple buttons in my form. now i have to call same modal in every button click and i want to show dynamically data in modal. What is solution?
推荐答案
您可以将动态变量传递给函数,然后在该函数中使用该变量手动"打开模式:
You can pass a dynamic variable to a function and then in the function you can use that variable to 'manually' open the modal:
<button class="btn btn-primary tag_cnt" style="top:144px; left:510px" onclick="showModal('data')" type="button" value="1"></button>
在您的JavaScript中,您可以像这样访问它:
In your javascript you can access that like this:
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();
}
这篇关于如何以一种引导方式绑定动态数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文