【问题标题】:How to add iframe to a div with jquery如何使用 jquery 将 iframe 添加到 div
【发布时间】:2013-02-02 01:13:17
【问题描述】:

我在接受的答案here中找到了这个代码... 将 iframe 加载到特定区域 通过按钮单击...

<a href="#" onclick="setIframe(this,'http://www.stackoverflow.co.uk')" >Set the Iframe up</a>

function setIframe(element,location){
    var theIframe = document.createElement("iframe");
    theIframe.src = location;
   element.appendChild(theIframe);
}

如何更改它以允许我设置高度宽度和滚动样式?

【问题讨论】:

    标签: javascript jquery iframe


    【解决方案1】:

    这不是 jQuery,而是纯 Javascript:

    function setIframe(element,location){
        var theIframe = document.createElement("iframe");
        theIframe.src = location;
        theIframe.setAttribute("weight", "500");
        theIframe.setAttribute("width", "500");
        theIframe.setAttribute("scrolling", "yes");
        element.appendChild(theIframe);
    }
    

    这不是您的问题的一部分,但这里是您如何使用 jQuery 切换 div:

    标记:

    <input type="button" value="Toggle Div"  id="btnToggle"/>
    
        <div id="randomContent">
            This is random Content.
            <br />
            This is random Content.
            <br />
            This is random Content.
            <br />
            This is random Content.
            <br />
            This is random Content.
            <br />
            This is random Content.
            <br />
        </div>
    

    jQuery:

        $(document).ready(function () {
            $("#btnToggle").bind("click", function () {
                $("#randomContent").toggle();
            });
        });
    

    【讨论】:

    • 如果我不想或“不应该”放入 iframe 但我希望 div 根据两个不同的按钮切换隐藏和显示...我问了一个单独的问题stackoverflow... 将很快发布链接
    • 谢谢...这是链接。有两个按钮。一个是提交表格,另一个是显示表格。 stackoverflow.com/questions/14651706/…
    【解决方案2】:
    theIframe.style.*
    

    您想要设置样式的任何属性。

    【讨论】:

      猜你喜欢
      • 2021-01-24
      • 2016-07-14
      • 1970-01-01
      • 2010-12-09
      • 2017-04-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多