添加列表项

<html>
<head>
</head>
<body>
  <P>
    <input type="text" id="txt"/>
    <input type="button" value="添加" id="but"/>
  </P>
  <ul id="ul">
    <li id="li">Java</li>
    <li id="li">JavaScript</li>
    <li id="li">PHP</li>
  </ul>
  <script>
    var txt = document.getElementById('txt');
    var but = document.getElementById('but');
    var ul = document.getElementById('ul');

    but.onclick = function(){
      var li = document.createElement('li');
      li.innerHTML = txt.value;
      ul.appendChild(li);
      txt.value = '';
    }
  </script>
</body>
</html>

猜你喜欢

转载自www.cnblogs.com/shu-xi/p/11819699.html