如何获得Twitter Bootstrap Modal的调用元素? [英] How to get Twitter Bootstrap Modal's invoker element?
本文介绍了如何获得Twitter Bootstrap Modal的调用元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个一个
元素用于调用模态:
I have got a a
element for invoking modal:
<a class="btn" data-toggle="modal" data-target="#myModal" href="http://some-url" >Launch Modal</a>
而且,这是我的模态:
<div class="modal hide" id="myModal">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h3>Modal header</h3>
</div>
<div class="modal-body">
<p>One fine body…</p>
</div>
<div class="modal-footer">
<a href="#" class="btn" data-dismiss="modal">Close</a>
<a href="#" class="btn btn-primary">Save changes</a>
</div>
</div>
我可以将函数绑定到由模态触发的事件:
I can bind functions to events fired by modal:
$('#myModal').on('hidden', function () {
// do something…
})
我的问题是:如何访问 a
元素 - 从我的事件订阅者函数调用模态?
My question is: How can i access the a
element -which invoked the modal- from my event subscriber function?
推荐答案
由于<$ c $,它在Bootstrap 3.0.0中得到了解决c> event.relatedTarget 。
$('#your-modal').on('show.bs.modal', function (e) {
var $invoker = $(e.relatedTarget);
});
这篇关于如何获得Twitter Bootstrap Modal的调用元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文