把<select>中option的转换为数组,并根据option text的值,设置选中,并刷新

来源:互联网 发布:网络电视十大排行榜 编辑:程序博客网 时间:2024/06/10 20:09
        function GetSelectTextArray() {            var array = new Array();  //定义数组               $("#MachineList option").each(function () {  //遍历所有option                  var txt = $(this).text();   //获取option值                   if (txt != '') {                    array.push(txt);  //添加到数组中                  }            })            return array;        }        function SetMachineSelected() {            var Machine = $("#txtMachineParam").val();            var MachineText = GetSelectTextArray();            var SelectIndex = MachineText.indexOf(Machine);            //$('#MachineList').get(0).selectedIndex = 4;            $('#MachineList')[0].selectedIndex = SelectIndex;            console.log("test---" + Machine + MachineText + SelectIndex)            $('#MachineList').multiselect('refresh');        }

阅读全文
0 0
原创粉丝点击