我有一个引导模式,它是由同一个页面中的两个链接触发的,我想传递一些参数来通知对话框它是从哪个元素触发的。因此,我可以在我的对话框gsp中检查这个参数。
第一环节
<a href="#" id="editCourseModal" data-toggle="modal" data-target="#createCourseModal" data-backdrop="static" data-keyboard="false">第二个按钮:
<button type="button" class="form-group btn btn-md btn-default"
data-toggle="modal" data-target="#createCourseModal" data-backdrop="static" data-keyboard="false">模态对话:
<div id="createCourseModal" tabindex="-1" role="dialog" arialabelledby="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-hidden="true">×</button>
<h4 class="modal-title" id="myModalLabel">Modal title</h4>
</div>
<div class="modal-body edit-content">
...
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>我想在我的对话框中检查这个参数(g:如果是test=“这个参数”),这样我就可以在此基础上实现、隐藏和显示一些html元素。有可能这样做吗?还有其他人想办法解决这个问题吗?
发布于 2015-11-06 09:13:04
您可以使用要发送的参数向每个触发器按钮添加一个数据属性,并执行以下操作
$('#createCourseModal').on('show.bs.modal', function (event) {
var button = $(event.relatedTarget) // Button that triggered the modal
var parameter = button.data('yourDataAttributeName') // Extract info from data-* attributes
var modal = $(this)
if (parameter == X) {
modal.find('.modal-title').text('Clicked by X');
} else {
modal.find('.modal-title').text('Clicked by Y');
}
})发布于 2015-11-06 09:10:25
在加载带有数据属性的模型中,您可以使用jQuery在元素的特定单击中打开该模型。
例如,假设您有两个锚链接:
<a href="#" id="link1"></a>
<a href="#" id="link2"></a>您可以使用这样的方式打开模式:
$('#link1').click(function() {
$('#myModal').modal('show');
// Here you could hide/show certain elements, and change this for #link2
});或者,你可以有两个模特儿。
发布于 2015-11-06 09:34:50
您可以相应地将数据id添加到按钮中,并使用j-query链接捕获该属性。
$(document).on("click", ".openModal", function () {
var clickedBy = $(this).data('id');
$(".modal-body").html(clickedBy)
});查找上述问题的以下链接
http://plnkr.co/edit/5EzNaDm1Z5SsXWngGULI?p=preview
https://stackoverflow.com/questions/33562981
复制相似问题