Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何通过添加表单将表单中的文本添加到iframe_Javascript_Html_Aframe - Fatal编程技术网

Javascript 如何通过添加表单将表单中的文本添加到iframe

Javascript 如何通过添加表单将表单中的文本添加到iframe,javascript,html,aframe,Javascript,Html,Aframe,有一个按钮可以添加新表单,如何向iframe添加文本 第一个表单将文本添加到场景中。但是,单击按钮创建的以下表单不显示文本 如何组合两个代码?文件引用 $(文档).ready(函数(){ var max_字段=10; 变量包装器=$(“.container1”); var add_button=$(“.add_form_field”); var x=1; $(添加按钮)。单击(功能(e){ e、 预防默认值(); 如果(x{ e、 预防默认值(); setAttribute(“文本”,“值”,

有一个按钮可以添加新表单,如何向iframe添加文本

第一个表单将文本添加到场景中。但是,单击按钮创建的以下表单不显示文本 如何组合两个代码?文件引用

$(文档).ready(函数(){
var max_字段=10;
变量包装器=$(“.container1”);
var add_button=$(“.add_form_field”);
var x=1;
$(添加按钮)。单击(功能(e){
e、 预防默认值();
如果(x”);//添加输入框
}
其他的
{
警报(“您已达到极限”)
}
});
$(包装器)。在(“单击”,“删除”,函数(e){
e、 preventDefault();$(this).parent('div').remove();x--;
})
});
$(“#text1”)。单击(函数(e){
var wrapper=document.getElementById(“文本容器”);
变量位置=新的三个向量3(wrapper.children.length*-1.1,0,0);
var newText=document.createElement('a-entity'))
newText.setAttribute('position',position)
newText.setAttribute(“文本”{
“颜色”:“白色”,
“对齐”:“居中”,
“值”:document.querySelector('#fname').value
})
appendChild(newText)
返回错误
});
表单{
位置:绝对位置;
z指数:1;
背景:白色;
填充:1em;
}

添加新字段+ 添加新字段+
首先,如果页面上有多个文本区域和按钮,则不能使用相同的ID(
#text
#fname
)来引用它们。你要么给他们唯一的ID,要么使用类名。此外,您还必须在相应的按钮上收听单击事件,而不仅仅是第一个按钮

最干净的设置方法是在同一函数中创建HTML文本区域和A-Frame文本输出:

函数createTextArea(包装器){
常数newTextArea=$(`
`);
append(newTextArea);
常量inputText=newTextArea.find(“.inputText”);
const sendButton=newTextArea.find(“.sendButton”);
var aframewapper=document.getElementById(“文本容器”);
const index=aframewapper.children.length;
var位置=新的三个向量3(指数*-1.1,0,0);
var newText=document.createElement(“a实体”);
newText.setAttribute(“位置”,位置);
newText.setAttribute(“文本”{
颜色:“白色”,
对齐:“居中”,
值:`output${index}`
});
aframeWrapper.appendChild(newText);
发送按钮。单击(e=>{
e、 预防默认值();
setAttribute(“文本”,“值”,inputText.val());
});
}
$(文档).ready(函数(){
变量包装器=$(“.container1”);
var max_字段=10;
var add_button=$(“.add_form_field”);
//创建初始文本区域
createTextArea(包装器);
var x=1;
$(添加按钮)。单击(功能(e){
e、 预防默认值();
如果(x
表单{
位置:绝对位置;
z指数:1;
背景:白色;
填充:1em;
}

添加新字段
+

代码段不起作用,在第11行第85列抛出一个错误