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