【发布时间】:2013-11-27 18:29:19
【问题描述】:
是否可以将文本框添加到 iframe 中,并将其附加到 iframe 的 src 中。所以我创建了一个模式框,显示一个按钮供用户单击“添加按钮”
<div id="addFeature" class="openAdd">
<div>
<a href="#" title="Close" class="close">X</a>
<h2>Add...</h2>
<button class="text" type="button">Text</button>
</div>
</div>
当用户点击按钮时,我需要关闭模式框并添加一个文本框。以下 iframe 位于 main.html 中。如您所见,iframe 显示另一个 html 页面。
<div>
<iframe class="newIframe" id="newIframe" src="webpage.html" onload="iFrameOn();">
Your browser does not support Iframes
</iframe>
</div>
虽然我需要在webpage.html中添加文本框
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript" src="index.js"></script>
</head>
<body onload="iFrameOn();">
<div id="design">
</div>
</body>
</html>
JS:
addTextBox() {
var text = "'<div><input type='textbox'/></div>'"
var textbox = document.createElement('div');
textbox.innerHTML = text;
var addText = document.getElementById('div').src = "webpage.html";
addText.appendChild(textbox);
}
是否可以按照我的要求进行操作?
【问题讨论】:
-
是的,这是可能的,只要不违反Same-origin policy。到目前为止,您尝试过什么?
标签: javascript html iframe textbox