[英]Dynamically created form called via onclick disappears immediately Javascript
I have dynamically created a button in my Javascript function and called another function onclick, as shown below. 我在Javascript函数中动态创建了一个按钮,并调用了另一个函数onclick,如下所示。
streambtn = document.createElement("button");
streambtn.setAttribute("onclick","createattribute()");
The createattribute() method opens a subdivision within the dynamically created form and this function is as follows. createattribute()方法在动态创建的表单中打开一个细分,此函数如下。
function createattribute() {
inputval.innerHTML = "Provide a Stream name and click to add attribute-type pairs to yours stream.";
var input = document.createElement("input");
input.type = "text";
input.placeholder="Attribute name";
input.id="attr"+attrID;
input.className = "attr-textfield-style";
inputval.appendChild(input);
//Display the drop down menu
var newDiv=document.createElement('div');
var html = '<select>', attrtypes = typeGenerate(), i;
for(i = 0; i < attrtypes.length; i++) {
html += "<option value='"+attrtypes[i]+"'>"+attrtypes[i]+"</option>";
}
html += '</select>';
newDiv.className="attr-combobox-style";
newDiv.id="type"+attrID;
newDiv.innerHTML= html;
inputval.appendChild(newDiv);
attrID++;
alert("attrname id: "+input.id+" attrtype id: "+ newDiv.id);
}
The inputval is a division within the dynamically created form where the newly created form elements from the createattribute() function will be appended to. inputval是动态创建的表单中的一个分区,来自createattribute()函数的新创建的表单元素将附加到该表单元素上。 But the issue that I'm facing right now, is that though the method is correctly called, the form(dynamically created form) immediately disappears in a split second once the streambtn is clicked.
但是我现在面临的问题是,尽管正确地调用了该方法,但是一旦单击streambtn,表单(动态创建的表单)将立即在瞬间消失。 Once it is clicked, it displays the first line "Provide a Stream name and click to add attribute-type pairs to yours stream."
单击后,将显示第一行“提供流名称,然后单击以将属性类型对添加到您的流中”。 in a flash and disappears.
一瞬间消失。 Is there a way to keep it onscreen and then hide it depending on any conditions(like after the user finishes entering the data corresponding to that newly opened form-> created via createattribute() method)?
有没有一种方法可以将其保留在屏幕上,然后根据任何条件将其隐藏(例如,在用户完成输入对应于通过createattribute()方法创建的新打开的form->的数据之后)?
Add
type = "button"
as<button>
withouttype = "button"
will act as submit button and overclick
of thesubmit
buttopn, page will be unloaded.添加
type = "button"
为<button>
无type = "button"
将作为行动提交按钮,在click
了的submit
buttopn,页面将被卸载。
streambtn = document.createElement("button");
streambtn.type = 'button';
streambtn.setAttribute("onclick","createattribute()");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.