我的代码应该从 ComboBox 获取值并添加一个 <p> 元素

My code is supposed to get the value from ComboBox and add a <p> element

此代码应该从组合框中获取值,在网站中创建一个新段落并将组合框值放入该段落中。我似乎无法在互联网上找到可行的解决方案。这是代码:

var newParagraph = document.createElement("p");
var myDiv = document.getElementById("output");

comboBox.addEventListener("click", eventHandler);

function eventHandler(){
    var result = comboBox.options[comboBox.selectedIndex].value;
    addLabel(result);
}

function addLabel(result){
    var newContent = document.createTextNode(result);
    newParagraph.appendChild(newContent);
    document.body.myDiv.appendChild(newParagraph);    
}```

document.body下没有myDiv 属性。使用您在脚本中分配的 myDiv 变量。

function addLabel(result){
    var newContent = document.createTextNode(result);
    newParagraph.appendChild(newContent);
    myDiv.appendChild(newParagraph);    
}