document_createElement

1831 ワード

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

    <title></title>

    <script type ="text/javascript">

       

        window.onload = function () {



          

            document.getElementById("btnAdd").onclick = function () {

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

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

                //      ,          innerHTML  innerText

              //  linew.innerHTML = "  ";

                linew.innerHTML = prompt("      ");



                //     li     ul  

                ulList.appendChild(linew);

                ulList.insertBefore(linew, ulList.childNodes[0]);

            };



            var ulli = gel("ulList");

            var lis = ulli.childNodes;//        

            for (var i = 0; i < lis.length; i++) {

                lis[i].onclick = function () {

                    //  alert(this.innerHTML);//this         ,this      

                    if (confirm("      ?"))

                    {

                        this.parentNode.removeChild(this);//      

                    }

                    

                }

            }

           

        }

        function gel(id) { return document.getElementById(id); }

       



    </script>

</head>

<body>

    <input type ="button" id="btnAdd" value ="  " />

    <ul id="ulList">

        <li >  </li>

        <li >  </li>

        <li >  </li>

    </ul>

</body>

</html>