首页 > 其他 > 详细

dom 留言加强

时间:2015-01-03 17:09:51      阅读:232      评论:0      收藏:0      [点我收藏+]
<!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>

 

dom 留言加强

原文:http://www.cnblogs.com/mayufo/p/4199612.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!