javascript - 如何使用 jquery 将 iframe 添加到 div

标签 javascript jquery iframe

我在接受的答案中找到了这个代码 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);
}

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

最佳答案

这不是 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();
        });
    });

关于javascript - 如何使用 jquery 将 iframe 添加到 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14651232/

相关文章:

javascript - React Native,无法启动模拟器。原因 : No emulators found as an output

javascript - 对象不是 "require"端的 Koa 实例

javascript - 将前一行数据添加到动态生成的行中

javascript - Edge浏览器无法触发iframe onload

带有 iframe 的 Javascript 显示/隐藏 div 适用于除 IE 之外的所有内容

javascript - 从 0 开始 setInterval 循环

javascript - router-link 无法在 Vuejs 中正确创建链接

javascript - 纯 CSS 方法在显示 :table element? 内保持图像比例

c# - 如何通过 Javascript 调用重定向到另一个操作的 Controller 操作?

javascript - 在字符串中显示下载的 html