通过 onclick 调用的动态创建的表单立即消失 Javascript
Dynamically created form called via onclick disappears immediately Javascript
我在 Javascript 函数中动态创建了一个按钮并调用了另一个函数 onclick,如下所示。
streambtn = document.createElement("button");
streambtn.setAttribute("onclick","createattribute()");
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);
}
inputval 是动态创建的表单中的一个部分,其中将附加来自 createattribute() 函数的新创建的表单元素。但是我现在面临的问题是,尽管正确调用了该方法,但单击 streambtn 后,表单(动态创建的表单)会立即消失。单击后,它会立即显示第一行 "Provide a Stream name and click to add attribute-type pairs to yours stream." 并消失。有没有办法让它显示在屏幕上,然后根据任何条件隐藏它(比如在用户完成输入与新打开的表单对应的数据后 -> 通过 createattribute() 方法创建)?
Add type = "button"
as <button>
without type = "button"
will act as submit button and over click
of the submit
buttopn, page will be unloaded.
streambtn = document.createElement("button");
streambtn.type = 'button';
streambtn.setAttribute("onclick","createattribute()");
我在 Javascript 函数中动态创建了一个按钮并调用了另一个函数 onclick,如下所示。
streambtn = document.createElement("button");
streambtn.setAttribute("onclick","createattribute()");
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);
}
inputval 是动态创建的表单中的一个部分,其中将附加来自 createattribute() 函数的新创建的表单元素。但是我现在面临的问题是,尽管正确调用了该方法,但单击 streambtn 后,表单(动态创建的表单)会立即消失。单击后,它会立即显示第一行 "Provide a Stream name and click to add attribute-type pairs to yours stream." 并消失。有没有办法让它显示在屏幕上,然后根据任何条件隐藏它(比如在用户完成输入与新打开的表单对应的数据后 -> 通过 createattribute() 方法创建)?
Add
type = "button"
as<button>
withouttype = "button"
will act as submit button and overclick
of thesubmit
buttopn, page will be unloaded.
streambtn = document.createElement("button");
streambtn.type = 'button';
streambtn.setAttribute("onclick","createattribute()");