Blogger Information
Blog 1
fans 0
comment 0
visits 681
Related recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
0711留言实战
Finestudio JZ的博客
Original
689 people have browsed it

<!DOCTYPE html>

<html>

    <head>

    </head>

    <body>

       <div>

         <label>请输入名称:</label><input id="comment">

           <ul id="list">

           </ul>

        </div>

        <script>

//创建变量

            var comment = document.getElementById("comment");

            var list = document.getElementById("list");

//触发事件           

            comment.addEventListener("keypress",addComment1);

//根据上课步骤使用了AppendChild function

            function addComment(event){

//                console.log(event.key); 

                if(event.key == 'Enter'){

                    var li  =document.createElement("li");

                    var output = comment.value;

                    li.innerHTML= output;

                    list.appendChild(li);   

                    comment.value= null;

                }

            }

//最新评论放在最上面 学习和使用了insertBefore function, createElement function

            function addComment1(event){

                  if(event.key == 'Enter'){

                      var li  =document.createElement("li");

                      var output = comment.value + "&nbsp;&nbsp;<button id='del' >删除</button>";

                      li.innerHTML= output;

                      if( list.hasChildNodes() ){

                          var first = list.firstElementChild;

                          list.insertBefore(li,first); 

                      }else{                          

                          list.appendChild(li);      

                      }

                        comment.value= null;

                }

            }

//学习并运用了currentTarget 和 target。

            var deleteBtn = document.getElementById('del');

            list.addEventListener('click',del);

            function del(event){

                event.currentTarget.removeChild(event.target.parentElement);

            }

        </script>

    </body>

</html>

//总结:

// 如何使用insertBefore function:    parentNode.insertBefore(newNode, firstChildNode);

//target and currentTarget

微信截图_20190716191102.png

转化HTML Collection to Array (slice(). splice() )

convert html collection to array.png







Correction status:qualified

Teacher's comments:这个作业主要是检测你对DOM操作的掌握情况, 看来你明白了, 但还要多多练习
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