欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

 更新時間:2013年12月02日 14:27:16   作者:  
幾乎HTML所有標(biāo)記都可以說是HTML的控件,如select, input, div, table等。html標(biāo)簽便捷的操作,深受大家的喜歡。如何使用javascript來操作HTML控件,下面我介紹下比較麻煩的幾個控件

復(fù)制代碼 代碼如下:

//下拉列表的填充

 _showSchools: function (data) { //data代表是一個數(shù)據(jù)對象

                var mySelect = document.getElementById("selectSchools"); //獲取下拉框
                mySelect.options.length = 0;
                //將option添加到select標(biāo)簽里面
                for (var index in data) {
                    var item = data[index];
                    var opp = new Option(item.SchoolName, item.name);  //第一個參數(shù)代表下拉框顯示的內(nèi)容,第二個代表下拉框選中的內(nèi)容
                    opp.name = "option" + index;
                    mySelect.add(opp);
                }
            },

//下拉列表內(nèi)容的獲取
var schoolId = document.getElementById("selectSchools").value;

//我們平時是選中下拉框的值是選中的內(nèi)容,而不是顯示的內(nèi)容,如何獲取顯示的內(nèi)容呢,下面是獲取下拉框的選中的顯示內(nèi)容
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);
}

//單選按鈕的內(nèi)容的獲取
 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);
                    }
                }

//單選按鈕的設(shè)置
if (entity.SelectType == 1) document.getElementById("SelectType").checked = true;
if (entity.SelectType == 0) document.getElementById("UnSelectType").checked = true;

//多選框的設(shè)置
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;
                    }
                }

            },

相關(guān)文章

最新評論