Blogger Information
Blog 20
fans 0
comment 0
visits 14139
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
ToList留言板-2019年1月17日22点18分
kszyd的博客
Original
743 people have browsed it

实例

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>ToList练习</title>
</head>
<body>
    <h3>留言板</h3>
    <input type="text">
    <ul></ul>
    <script>
        var comment=document.querySelector('input');
        var ul=document.getElementsByTagName('ul')[0];
        comment.focus();
        // event 代表事件对象
        comment.onkeydown=function(event) {
              if (event.keyCode===13) {
                var li=document.createElement('li');
                li.innerHTML=comment.value+'<a href="javascrip:;" onclick="del(this)">删除</a>';
              if(ul.childElementCount===0){
                ul.appendChild(li);
              } else {
                  var first=ul.firstElementChild;
                  ul.insertBefore(li,first);
              }                
                comment.value ='';
              }              
        }
        function del(ele){
            if(confirm('要删除吗')) {
                ele.parentNode;
                var li=ele.parentNode;
                li.parentNode.removeChild(li);
            }
        }
    </script>
</body>
</html>

运行实例 »

点击 "运行实例" 按钮查看在线实例

Correction status:Uncorrected

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!