通过模态加载动态 URL [英] Load dynamic URL via modal
问题描述
假设我有以下链接由循环生成 X 次.
Let's say I have the following link that's generated X times by a loop.
<a class="btn" data-toggle="modal" data-target="#view_more" href="/item/view/<?php echo $item_id; ?>">Launch Modal</a>
这是启动模态的 JS 脚本.
Here's the JS script that initiates the modal.
$(document).ready(function () {
$('#view_more').modal({
remote: '/item/view/1',
show:false
}); // Start the modal
它在 remote
url 被硬编码时有效,但我希望它是动态的,具体取决于传递给它的内容.
It works when the remote
url is hardcoded, but I would like it to be dynamic depending on what gets passed to it.
推荐答案
Modal 插件在其构造函数中执行 load()
方法,所以真的是改变 Modal 远程内容的唯一方法(除了自己手动执行 AJAX)是在执行另一个调用之前销毁它:
The Modal plugin executes the load()
method in it's constructor, so really the only way to change the remote content of a Modal (other than manually doing the AJAX yourself) is to destroy it before doing another call:
$('#view_more')
.removeData('modal')
.modal({
remote: someURL,
show: false
});
回答类似帖子有更多详细信息:Twitter 引导远程模式每次都显示相同的内容
There are more details in answer to a similar post: Twitter bootstrap remote modal shows same content everytime
这篇关于通过模态加载动态 URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!