首页 > 代码库 > jszs 枚举算法

jszs 枚举算法

<!doctype html><html><head><meta charset="utf-8"><title>无标题文档</title><script>window.onload = function (){    var oa = document.getElementsByTagName(‘a‘);    var oul = document.getElementById(‘ul1‘);    var ali = oul.getElementsByTagName(‘li‘);        for(var i = 0; i < oa.length; i++)    {        oa[i].onclick = function ()        {            if(mj(this.innerHTML))            {                var oli = document.createElement(‘li‘);                oli.innerHTML = this.innerHTML;                if(!ali[0])                {                    oul.appendChild(oli);                }                else                {                    oul.insertBefore(oli,ali[0]);                }            }            else            {                mj2(this.innerHTML);            }        }    }        function mj(text)    {        for(var i = 0; i < ali.length; i++)        {            if(text == ali[i].innerHTML)            {                return false;            }        }        return true;    };        function mj2(text)    {        for(var i = 0; i < ali.length; i++ )        {            if(text == ali[i].innerHTML)            {                oul.insertBefore(ali[i],ali[0]);            }        }    }    }</script></head><body><a href="javascript:;">北京</a><a href="javascript:;">上海</a><a href="javascript:;">西安</a><a href="javascript:;">深圳</a><a href="javascript:;">香港</a><a href="javascript:;">杭州</a><a href="javascript:;">澳门</a>  </ul><ul id="ul1"></ul></body></html>

 

jszs 枚举算法