我正在以编程方式创建文本框,但是我面临的问题是,当我将其作为要插入列表顶部的对象插入数组时,允许的类型是label。因此,当显示文本框时,程序不允许文本框供用户输入。有没有办法来解决这个问题?我已经尝试过将类型更改为文本,但无法定义。
searchArray = [];
//creating the text box and placing it in a variable
var textBox = "<input type='text' placeholder='Search Client Code'>";
searchArray.push({label: textBox });
//diaplaying the text box in a context menu sub menu
return{
"Search" : {
label : "Search",
action: true,
"submenu": searchArray,
disabled: false
}
}
*****************************************************
UPDATE
var searchArray = [];
var textBox = "<input type='text' placeholder='Search Client Code'>";
textBox.push({label: something});
//this array is used to insert the textbox and also the clients afterwards
new_array = [];
new_array.push(searchArray[0]);
//the below push is used in a for loop that loops each client,
//so I am just putting it here just for reference
***
new_array.push(itemDisp[i]);
***
if(...){
var obj = {
"DuplicateFor" : {
label : "Duplicate for",
action: true,
"submenu": new_array,
disabled: false
}
}
document.body.innerHTML = obj['DuplicateFor']['submenu'][0].label
}
答案 0 :(得分:2)
尝试一下。它将成功创建输入并同时接受输入
var searchArray = [];
//creating the text box and placing it in a variable
var textBox = "<input type='text' placeholder='Search Client Code'>";
searchArray.push({
label: textBox
});
//diaplaying the text box in a context menu sub menu
var obj = {
"Search": {
label: "Search",
action: true,
"submenu": searchArray,
disabled: false
}
}
console.log(obj)
document.body.innerHTML = obj['Search']['submenu'][0].label