How to get Twitter Bootstrap Modal#39;s invoker element?(如何获取 Twitter Bootstrap Modal 的调用者元素?)
问题描述
我有一个用于调用模态的 a 元素:
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>
而且,说这是我的模态:
And, say this is my modal:
<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?
推荐答案
由于 event.relatedTarget 在 Bootstrap 3.0.0 中解决了.
It was solved in Bootstrap 3.0.0 thanks to event.relatedTarget.
$('#your-modal').on('show.bs.modal', function (e) {
  var $invoker = $(e.relatedTarget);
});
                        这篇关于如何获取 Twitter Bootstrap Modal 的调用者元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何获取 Twitter Bootstrap Modal 的调用者元素?
				
        
 
            
        基础教程推荐
- 原生拖动事件后如何获取 mouseup 事件? 2022-01-01
 - Bokeh Div文本对齐 2022-01-01
 - npm start 错误与 create-react-app 2022-01-01
 - 在 contenteditable 中精确拖放 2022-01-01
 - 即使用户允许,Gmail 也会隐藏外部电子邮件图片 2022-01-01
 - Fabric JS绘制具有活动形状的多边形 2022-01-01
 - 如何添加到目前为止的天数? 2022-01-01
 - Bootstrap 模态出现在背景下 2022-01-01
 - 检查 HTML5 拖放文件类型 2022-01-01
 - fetch 是否支持原生多文件上传? 2022-01-01
 
    	
    	
    	
    	
    	
    	
    	
    	
						
						
						
						
						
				
				
				
				