gpt4 book ai didi

javascript - 从另一个页面打开 Bootstrap 模式

转载 作者:行者123 更新时间:2023-11-30 10:19:09 25 4
gpt4 key购买 nike

我有一个链接列表,每个链接都打开自己的模式。这些模式内容中的每一个都显示一个 html 文件。这是一个示例;

<div id="how-rtm-works" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h1 id="myModalLabel">How Right to Manage works</h1>
</div>
<div class="modal-body" id="utility_body">
<p>One fine body…this is getting replaced with content that comes from passed-in href</p>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<li><a data-target="#how-rtm-works" href="modal-content/how-RTM-works.html" role="button" data-toggle="modal">How Right to Manage works</a></li>

因为有多个模态框,每个模态框都有自己的 ID,在数据目标中引用。

任何人都可以告诉我如何从另一个页面定位这些模式,或者在我的情况下,所有页面都将链接到网站页脚导航中。

最佳答案

您将使用的第一页:

<a href="second.html#myModalLabel" class="btn btn-primary"> Open Modal </a>

在第二页,您将插入模态框和以下脚本:

        <script type='text/javascript'>
(function() {
'use strict';
function remoteModal(idModal){
var vm = this;
vm.modal = $(idModal);

if( vm.modal.length == 0 ) {
return false;
}

if( window.location.hash == idModal ){
openModal();
}

var services = {
open: openModal,
close: closeModal
};

return services;
///////////////

// method to open modal
function openModal(){
vm.modal.modal('show');
}

// method to close modal
function closeModal(){
vm.modal.modal('hide');
}
}
Window.prototype.remoteModal = remoteModal;
})();

$(function(){
window.remoteModal('#myModalLabel');
});
</script>

关于javascript - 从另一个页面打开 Bootstrap 模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22203177/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com