我想将参数传递给模态窗口,例如标题。
所以我添加了data-title
到我的链接 <a data-toggle="modal" href="#myModal" class="btn" data-title="Title goes here">Launch demo modal</a>
当然,当模式打开时,我想替换默认标题
...
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Modal title</h4>
</div>
...
我的 JS 是这样的,但它没有设置正确的标题。
$('.modal-body', "#ModalWindow").html('<%= j render(template: "tasks/new.html.erb") %>');
var Title = $(this).data('title');
$(".modal-title, #ModalWindow").text( Title );
$("#ModalWindow").modal('show');
感谢您的帮助。
最佳答案
我认为你的问题是这一行:
$(".modal-title, #ModalWindow").text( Title );
应该是:
$(".modal-title", "#ModalWindow").text( Title );
关于jquery - 具有 Bootstrap 模式的数据属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18704063/