Javascript 为什么赢了';当使用JS创建时,我的选择是否会显示一个选项?
这似乎并没有创建下拉列表,即使我创建了一个附加在select中的option元素,也没有用于Arial的选项Javascript 为什么赢了';当使用JS创建时,我的选择是否会显示一个选项?,javascript,html,css,Javascript,Html,Css,这似乎并没有创建下拉列表,即使我创建了一个附加在select中的option元素,也没有用于Arial的选项 const sheets=document.getElementById('sheets'); const siteDocument=document.getElementsByTagName('body')[0]; const popup=document.getElementById('popup'); const buttons=document.getElementById('
const sheets=document.getElementById('sheets');
const siteDocument=document.getElementsByTagName('body')[0];
const popup=document.getElementById('popup');
const buttons=document.getElementById('buttons');
constToolResult=document.getElementById('toolresult');
const item=document.getElementById('item');
//const sheets=document.getElementById('sheets');
/*弹出窗口*/
const myStuff=prompt('Enter'列,行\'注:建议在计算机上使用5,20,请参阅文档');
if(myStuff!=''| | myStuff.includes(',')==true){
常量myStuffArr=myStuff.split(',');
console.log(myStuffArr);
window.amountOfColumns=myStuffArr[0];
window.amountOfRows=myStuffArr[1];
}否则{
window.amountOfColumns=5;
window.amountOfRows=20;
}
/*功能*/
const itemVisible=document.getElementById('itemVisible');
功能变更项目(测试){
itemVisible.value=test.slice(test.indexOf('t')+1,test.length);
}
函数showProperties(){
const forButton=document.createElement('select');
forButton.setAttribute('type','text')
toolresult.appendChild(forButton)
const option=document.createElement('option');
option.setAttribute('value','Arial')
forButton.appendChild(选项)
}
var计数器=0;
对于(var x=0;x 对于(var j=1;j请尝试以下内容。我已更改了行文档.getElementById('toolresult').appendChild(forButton))以及如何向选项添加值和html
function showProperties() {
const forButton = document.createElement('select');
forButton.setAttribute('type', 'text')
toolresult.appendChild(forButton)
const option = document.createElement('option');
option.setAttribute('value', 'Arial')
forButton.appendChild(option)
}
完整代码如下
const sheets=document.getElementById('sheets');
const siteDocument=document.getElementsByTagName('body')[0];
const popup=document.getElementById('popup');
const buttons=document.getElementById('buttons');
constToolResult=document.getElementById('toolresult');
const item=document.getElementById('item');
//const sheets=document.getElementById('sheets');
/*弹出窗口*/
const myStuff=prompt('Enter'列,行\'注:建议在计算机上使用5,20,请参阅文档');
if(myStuff!=''| | myStuff.includes(',')==true){
常量myStuffArr=myStuff.split(',');
console.log(myStuffArr);
window.amountOfColumns=myStuffArr[0];
window.amountOfRows=myStuffArr[1];
}否则{
window.amountOfColumns=5;
window.amountOfRows=20;
}
/*功能*/
const itemVisible=document.getElementById('itemVisible');
功能变更项目(测试){
itemVisible.value=test.slice(test.indexOf('t')+1,test.length);
}
函数showProperties(){
const forButton=document.createElement('select');
document.getElementById('toolresult').appendChild(forButton)
const option=document.createElement('option');
option.value='Arial';
option.innerHTML='Arial';
forButton.appendChild(选项)
}
var计数器=0;
对于(var x=0;x 对于(var j=1;jdid,您是否将forButton
附加到文档中?@Nick yes,它被附加到toolresult,这是我没有包含的一个div。
function showProperties() {
const forButton = document.createElement('select');
document.getElementById('toolresult').appendChild(forButton)
const option = document.createElement('option');
option.value = 'Arial';
option.innerHTML = 'Arial';
forButton.appendChild(option)
}