我已经在我的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,表单(动态创建的表单)会立即消失。单击它后,它将显示第一行“提供流名称,然后单击以向您的流添加属性类型对”。一瞬间就消失了。有没有办法让它保持在屏幕上,然后根据任何条件隐藏它(比如在用户完成输入与新打开的表格相对应的数据后,>通过createattribute()方法创建)?
答案 0 :(得分:1)
将
type = "button"
添加为<button>
type = "button"
,click
将作为提交按钮,而submit
buttopn的streambtn = document.createElement("button"); streambtn.type = 'button'; streambtn.setAttribute("onclick","createattribute()");
将会卸载页面。
var o={
"StudentInfo": [{
"Name1": [{
"100": {
"a": "12"
}
}, {
"101": {
"a": "50"
}
}]
}, {
"Name2": [{
"102": {}
}, {
"103": {
"b": "50"
}
}]
}]
}