您的位置:首页 > 运维架构

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

2017-11-01 16:52 411 查看
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');
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: