冯海滨博客

当前位置:   网站首页 >> Jquery

js 操作ul li

--------------------广告位招租--------------------
 function kefushengfentianjia() {
            var shengfen = document.getElementById("selectshengfen"); //定位id
            var shengfenindex = shengfen.selectedIndex; // 选中索引
            var shengfentext = shengfen.options[shengfenindex].text; // 选中文本

            var kefu = document.getElementById("selectkefu"); //定位id
            var kefuindex = kefu.selectedIndex; // 选中索引
            var kefutext = kefu.options[kefuindex].text; // 选中文本
 
 
            var jieguoul = document.getElementById("ultianjia");
            var jieguolist = jieguoul.getElementsByTagName("li");
            var jianchajieguo = false;
            for (var i = 0; i < jieguolist.length; i++) {
                var litext = jieguolist[i].textContent;
                var litextadd = shengfentext + "-" + kefutext;
                if (litext == litextadd) {
                    jianchajieguo = true;
                }
            }

            if (jianchajieguo == false) {
                var litextadd = shengfentext + "-" + kefutext;
                var li = document.createElement("li");
                li.innerHTML = litextadd;
                li.setAttribute("id", "newli");
                var ul = document.getElementById("ultianjia");
                ul.appendChild(li);
            }
            else {
                alert("已经添加过了 请勿重复添加!");
            }
        }

 


--------------------广告位招租--------------------

发表我的评论

Hi,您需要填写昵称和邮箱!

  • 必填项