2

我在此处接受的答案中找到了此代码...它通过单击按钮将 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);
}

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

4

2 回答 2

2
theIframe.style.*

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

于 2013-02-01T16:59:38.010 回答
2

这不是 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();
        });
    });
于 2013-02-01T17:00:19.447 回答