javascript操作html控件实例(javascript添加html)

代码如下:

//下拉列表的填充

 _showSchools: function (data) { //data代表是一个数据对象


                var mySelect = document.getElementById("selectSchools"); //获取下拉框
                mySelect.options.length = 0;
                //将option添加到select标签里面
                for (var index in data) {
                    var item = data[index];
                    var opp = new Option(item.SchoolName, item.name);  //第一个参数代表下拉框显示的内容,第二个代表下拉框选中的内容
                    opp.name = "option" + index;
                    mySelect.add(opp);
                }
            },


//下拉列表内容的获取
var schoolId = document.getElementById("selectSchools").value;


//我们平时是选中下拉框的值是选中的内容,而不是显示的内容,如何获取显示的内容呢,下面是获取下拉框的选中的显示内容
function on_idmbzd_change(){ 
    var sel_obj=document.getElementById("idMbzd");
    var index=sel_obj.selectedIndex;
    alert(sel_obj.options[index].value);
    alert(sel_obj.options[index].text);
}


//单选按钮的内容的获取
 var chkObjs = document.getElementsByName("radio");
                var checkvalue = null;
                for (var i = 0; i < chkObjs.length; i++) {
                    if (chkObjs[i].checked) {
                        checkvalue = parseInt(chkObjs[i].value);
                    }
                }


//单选按钮的设置
if (entity.SelectType == 1) document.getElementById("SelectType").checked = true;
if (entity.SelectType == 0) document.getElementById("UnSelectType").checked = true;


//多选框的设置
setCheckBox: function (data) {
                var courseList = document.getElementsByName("CourseList");
                for (var i = 0; i < courseList.length - 1; i++) {
                    if (courseList[i].value==data) {
                        courseList[i].checked=true;
                    }
                }


            },

相关推荐