zoukankan      html  css  js  c++  java
  • dom 留言加强

    <!doctype html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>无标题文档</title>
    <script type="text/javascript">
    window.onload = function ()
    {
        var otext = document.getElementById('text1');
        var obtn1 = document.getElementsByTagName('input')[1];
        var obtn2 = document.getElementsByTagName('input')[2];
        var oul = document.getElementById('ul1');
        var flag = 1;
        
        obtn1.onclick = function ()
        {
            if(!otext.value)
            {
                return ;
            }
            var oli = document.createElement('li');
            oli.innerHTML = otext.value;
            
            if(oul.children[0])
            {
                oul.insertBefore(oli,oul.children[0]);
            }
            else
            {
                oul.appendChild(oli);
            }
            
            otext.value = '';
            
            for( var i = 0 ;i < oul.children.length; i++)
            {
                oul.children[i].onclick = function ()
                {
                    if(flag)
                    {
                        this.mark = '1';
                        this.style.background = 'yellow';
                    }
                    else
                    {
                        this.mark = '';
                        this.style.background = '';
                    }
                    flag = !flag;
                }
            }
            
            
        };
        
        obtn2.onclick = function ()
        {
            for(var i = 0; i < oul.children.length; i++)
            {
                if(oul.children[i].mark)
                {
                    oul.removeChild(oul.children[i]);
                    i--;
                }
            }
        }
    };
    </script>
    </head>
    
    <body>
    <input type="text" id="text1">
    <input type="button" value="留言">
    <input type="button" value="批量删除">
    <ul id="ul1">
    </ul>
    </body>
    </html>
  • 相关阅读:
    从当前url替换获得新的url
    访问者模式
    备忘录模式
    make makefile cmake qmake 区别
    qt编译过程
    tensorflow前处理
    tesorflow操作
    tensorflow的object_detection安装
    tensorflow 编译与训练
    tensorflow后处理
  • 原文地址:https://www.cnblogs.com/mayufo/p/4199612.html
Copyright © 2011-2022 走看看