vincenshen

HTML代码

   <div>
        <input type="text" id="inp">
        <input type="button" value="添加" onclick="addElement()">
        <ul id="container">
            <li>内容1</li>
        </ul>

    </div>

JS代码

   function addElement(){
            var val = document.getElementById("inp").value;
            var tag = document.createElement("li");
            tag.innerText = val;
            document.getElementById("container").appendChild(tag);
            document.getElementById("inp").value = "";
        }

效果图

 

分类:

技术点:

相关文章:

  • 2021-09-26
  • 2021-12-10
  • 2022-01-13
  • 2021-12-19
  • 2021-12-15
  • 2021-11-23
  • 2022-02-09
  • 2022-01-08
猜你喜欢
  • 2021-07-08
  • 2021-10-06
  • 2021-12-06
  • 2021-12-05
  • 2021-12-05
  • 2021-11-23
  • 2021-04-05
相关资源
相似解决方案