Jquery 在引导模式中传递和检查参数

Jquery 在引导模式中传递和检查参数,jquery,twitter-bootstrap,gsp,Jquery,Twitter Bootstrap,Gsp,我有一个引导模式,它是由同一页面中的两个链接触发的,我想传递一些参数,通知对话框它是从哪个元素触发的。所以我可以在我的对话框gsp tempalte中检查这个参数 第一环节 <a href="#" id="editCourseModal" data-toggle="modal" data-target="#createCourseModal" data-backdrop="static" data-keyboard="false"> 第二个按钮: <button typ

我有一个引导模式,它是由同一页面中的两个链接触发的,我想传递一些参数,通知对话框它是从哪个元素触发的。所以我可以在我的对话框gsp tempalte中检查这个参数

第一环节

 <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">&times;</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:if test=“this parameter”),这样我就可以基于这个参数实现、隐藏和显示一些html元素。
有可能吗?有人有别的办法来解决这个问题吗

在使用数据属性加载模态的内部,您可以使用jQuery在元素的某个单击上打开模态

例如,假设您有两个锚链接:

<a href="#" id="link1"></a>
<a href="#" id="link2"></a>

或者,您可以有两个模态。

您可以为每个触发器按钮添加一个数据属性,其中包含要发送的参数,并执行类似操作

$('#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');
  }
})

您可以相应地向按钮添加数据id,并使用j-query链接捕获该属性

$(document).on("click", ".openModal", function () {
     var clickedBy = $(this).data('id');
     $(".modal-body").html(clickedBy)
});
找到上述问题的以下链接

$(document).on("click", ".openModal", function () {
     var clickedBy = $(this).data('id');
     $(".modal-body").html(clickedBy)
});