Bootstrap-模态-父对象的访问值 [英] Bootstrap - Modal - Access value of parent object
问题描述
我有一类链接,单击这些链接可以启动模式窗口.在模态窗口内,如何访问生成模态的对象的href?我的目标是在模式窗口中使用一个按钮,单击该按钮将打开一个呼叫者的href窗口.
I have a class of links which when clicked launch a modal window. Within the modal window how can I access the href of the object which spawned the modal? My goal is to use a button within the modal window which, when clicked will open a window to the href of the caller.
我不需要代码来显示此类链接的模式窗口,只需要如何从父对象获取值即可.
I don't need code to display the modal window for this class of links, just how to acccess values from the parent object.
谢谢
根据要求的示例:
<li><a href="http://foo" rel="ExtLink">blah</a></li>
<li><a href="http://bar" rel="ExtLink">Test</a></li>
模式:
<div class="modal fade" id="ModalTest" tabindex="-1" role="dialog" aria-labelledby="ModalTestLabel" 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="ModalTestLabel">External URL warning</h4>
</div>
<div class="modal-body">
External URL warning here.
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Exit</button>
<button type="button" class="btn btn-primary">I understand, visit link</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
从JS打开:
$("a[rel='ExtLink']").click(function(e){
$('ModalTest').show();
});
因此,如果我单击其中任意一个,则会打开一个模式窗口.在模式窗口中,我需要一个按钮,当按下该按钮时,它将启动调用者的href.谢谢
So if I click either of these a modal window opens. Within the modal window I want a button that when pressed launches the href of the caller. Thanks
推荐答案
尝试一下,
$(document).on("click", "ul li a", function (e) {
e.preventDefault();
e.stopPropagation();
var link = $(this).attr('href');
$("#myModal a").attr('href',link);
$(".moadl").modal("show");
});
html
<ul>
<li><a href="http://foo" rel="ExtLink">blah</a></li>
<li><a href="http://bar" rel="ExtLink">Test</a></li>
</ul>
<div class="modal hide" id="myModal">
<div class="modal-header">
<button class="close" data-dismiss="modal">×</button>
<h3>Modal header</h3>
</div>
<div class="modal-body">
<a href="">go to link</a>
</div>
</div>
这篇关于Bootstrap-模态-父对象的访问值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!