📜  javascript 按钮将输入添加到列表项 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:03:05.877000             🧑  作者: Mango

代码示例1
//Defining a listener for our button, specifically, an onclick handler
document.getElementById("add").onclick = function() {
    //First things first, we need our text:
    var text = document.getElementById("idea").value; //.value gets input values

    //Now construct a quick list element
    var li = "
  • " + text + "
  • "; //Now use appendChild and add it to the list! document.getElementById("list").appendChild(li); }