[英]jquery dialog not load iframe
我有這個代碼:
<div id="dialog">
<iframe id="myIframe" src=""></iframe>
</div>
<style>
#myIframe{
width: 100%;
height: 100%;
}
</style>
function showModalSettings(id){
alert(id);
$("#dialog").dialog({
autoOpen: false,
show: "fade",
hide: "fade",
modal: true,
open: function (ev, ui) {
$('#myIframe').src = 'https://www.onet.pl';
},
height: '600',
width: '800',
resizable: true,
title: 'Settings'
});
$('#dialog').dialog('open');
}
showModalSettings(12);
我需要在jquery對話框中打開https://www.onet.pl (在iframe中)。 當前代碼正確顯示了對話框 - 但沒有onet.pl網站。 iframe是空的
怎么解決?
使用jQuery,我們使用attr()
方法來修改HTML元素的屬性。
修復后的代碼如下所示:
function showModalSettings(id){ alert(id); $("#dialog").dialog({ autoOpen: false, show: "fade", hide: "fade", modal: true, open: function (ev, ui) { //$("#myIframe").src = "https://www.onet.pl"; $("#myIframe").attr("src", "https://www.onet.pl"); }, height: '600', width: '800', resizable: true, title: 'Settings' }); $('#dialog').dialog('open'); } showModalSettings(12);
#myIframe{ width: 100%; height: 100%; }
<!DOCTYPE html> <html> <head> <title>Hello, world!</title> <meta charset="utf-8" /> <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"> <script src="https://code.jquery.com/jquery-1.12.4.js"></script> <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script> </head> <body> <div id="dialog"> <iframe id="myIframe"></iframe> </div> </body> </html>
從以下鏈接了解有關attr()
更多信息: https : //api.jquery.com/attr/
附注:下次請顯示您正在使用的庫或框架(例如此問題中的jQuery UI),這對於想要回答您問題的人有所幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.