繁体   English   中英

jquery对话框未加载iframe

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM