Select相关操作

来源:互联网 发布:ubuntu卸载qq国际版 编辑:程序博客网 时间:2024/04/30 13:42

1.已经存在的Select控件,向其中动态添加Option

 var ddlSelect = document.getElementById("Select1");
                for (var i = 0; i < Childcategory.length; i++) {
                  
                    var option = document.createElement("option");
                    option.innerText = Childcategory[i];
                    option.value = ChildcategoryID[i];

                    ddlSelect.appendChild(option);
                }

2.已经存在的带有option的select,清除其中的option

方法1.document.getElementById("Select1").innerHTML = "";

方法2.

          var theSelect = document.getElementById("Select1");

                for (var i = theSelect.options.length - 1; i >= 0; i--)
                    theSelect.options.remove(i);  

 

 

附件:

初步根据json获取其下级内容

http://download.csdn.net/detail/hugaozhuang/4934591