[英]javascript - Issue with showing bootstrap modal dialog using javascript
I have a <div>
element defined in Navpane.html, it is a html navigation panel. 我在Navpane.html中定义了一个<div>
元素,它是一个html导航面板。
I am able to access this div using id from other html page but I am not able to show this dialog in the current frame. 我可以使用其他HTML页面的ID来访问此div,但无法在当前框架中显示此对话框。 It's throwing error. 抛出错误。
<div class="panel-body">
<div class="modal fade" id="TimeoutModal" 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" aria-hidden="true">×</button>
<h4 class="modal-title" id="myModalLabel">User logout warning</h4>
</div>
<div class="modal-body">
User session is going to expire within a minute . Do you want to retain the session?
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary">OK</button>
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
</div>
</div>
</div>
</div>
</div>
top.window.frames[1].document.getElementById("TimeoutModal"); top.window.frames [1] .document.getElementById(“ TimeoutModal”);
I am getting the div using javascript from the other frame and calling modal() function on this . 我从另一帧使用javascript获取div并在此调用modal()函数。 it is failing with the error message. 它失败并显示错误消息。
Uncaught TypeError: top.window.frames[1].document.getElementById(...).modal is not a function(…) 未捕获的TypeError:top.window.frames [1] .document.getElementById(...)。modal不是函数(...)
Thanks 谢谢
You need to get the jQuery element and call modal() on that. 您需要获取jQuery元素并在其上调用modal()。 If you are using bootstrap it should already be included in your page else add a reference to jQuery.js 如果您正在使用引导程序,则应该已经将其包含在页面中,否则请添加对jQuery.js的引用
$('#TimeoutModal', top.window.frames[1].document).modal();
or 要么
$('#TimeoutModal', top.window.frames[1].document).modal('show');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.