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

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

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

  2020-05-13 我要评论

复制代码 代码如下:

//下拉列表的填充

 _showSchools: function (data) { /https://img.qb5200.com/download-x/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;
                    }
                }

            },

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们