Javascript 将文本框添加到iframe中并附加到其他html中
是否可以将文本框添加到iframe中,并将其附加到iframe的src中。因此,我创建了一个模式框,其中显示一个按钮,供用户单击“添加按钮”Javascript 将文本框添加到iframe中并附加到其他html中,javascript,html,iframe,textbox,Javascript,Html,Iframe,Textbox,是否可以将文本框添加到iframe中,并将其附加到iframe的src中。因此,我创建了一个模式框,其中显示一个按钮,供用户单击“添加按钮” 添加 正文 当用户单击按钮时,我需要关闭模式框并添加一个文本框。以下iframe位于main.html中。如您所见,iframe显示了另一个html页面 <div> <iframe class="newIframe" id="newIframe" src="webpage.html" onload="iFrameOn();"&
添加
正文
当用户单击按钮时,我需要关闭模式框并添加一个文本框。以下iframe位于main.html中。如您所见,iframe显示了另一个html页面
<div>
<iframe class="newIframe" id="newIframe" src="webpage.html" onload="iFrameOn();">
Your browser does not support Iframes
</iframe>
</div>
您的浏览器不支持iFrame
虽然我需要在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=“”“
var textbox=document.createElement('div');
textbox.innerHTML=文本;
var addText=document.getElementById('div').src=“webpage.html”;
addText.appendChild(文本框);
}
有可能按我的要求去做吗?我担心用你现在尝试的方式来解释这一点,会是一片无尽的沼泽。这里有一些指导原则,你可以很容易地做到这一点 可能需要先从
iframe
标记中删除onload
。然后将这些行放到您的主页上:
var textForIframe; // Take care that this variable is declared in the global scope
function addText () {
document.getElementById('newIframe').src = 'webpage.html';
textForIframe = '<div><input type="text" /></div>'; // or whatever text you need
return;
}
这些代码段在
iframe
中向设计添加了一个新的input type=“text”
,是的,只要不违反规则,这是可能的。到目前为止你都尝试了什么?我怎样才能使文本框可以拖动和调整大小?嗯。。。这是一项复杂得多的任务,特别是对于纯JavaScript。我想你应该问一个新问题。我已经改变了我的应用程序,而不是webpage.html,我有一个iframe,在同一个域中操作。还可以在这个iframe中添加文本框吗。。。正如我在对你的问题的评论中所说的,是的,这是可能的。只需发布一个带有相关代码的新问题。。。顺便说一句,如果你在两个月后更改了你的应用程序,这不应该成为拒绝回答的理由,因为这对它被回答的应用程序是有效的。
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);
}
var textForIframe; // Take care that this variable is declared in the global scope
function addText () {
document.getElementById('newIframe').src = 'webpage.html';
textForIframe = '<div><input type="text" /></div>'; // or whatever text you need
return;
}
window.onload = function () {
var addTextElement = document.getElementById('design'), // or whatever element you want to use in iframe
textToAdd = parent.textForIframe;
// depending on what iFrameOn() does, place it here...
addTextElement.innerHTML = textToAdd;
iFrameOn(); // ... or it can be placed here as well
return;
};