javascript操作html控制項執行個體(javascript添加html)

來源:互聯網
上載者:User

複製代碼 代碼如下:
//下拉式清單的填充

 _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;
                    }
                }

            },

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.