【问题标题】:Return value from Bootstrap model to the element which is clicked to open modal从 Bootstrap 模型返回值到被点击打开模态的元素
【发布时间】:2015-03-17 05:07:36
【问题描述】:
我创建了一个引导模式。当我单击文本元素时它将打开。代码如下:
<input type="text" id="btnModel" >
$( "#btnModel" ).click(function() {
$('#myModal').modal('show')
});
当我点击模型中的一个按钮时,它应该设置输入文本元素btnModel(用于打开模式)的值。 modal如何访问用于打开modal的元素?
【问题讨论】:
标签:
jquery
twitter-bootstrap
bootstrap-modal
【解决方案1】:
您可以在按下的元素上添加一个类 pressedModal 以打开模式。
从模态中使用此类访问该元素,然后在模态关闭时删除此类:
$(document).on('click', '#btnModel', function() {
$(this).addClass('pressedModal');
$('#myModal').modal('show');
});
在模态窗口中:
$(document).on('click', '#button_in_modal', function() {
var buttonPressed = $('.pressedModal');
// do your stuff
});
$(document).on('click', '#close_modal', function() {
var buttonPressed = $('.pressedModal');
buttonPressed.removeClass('pressedModal');
});