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');
}
把<select>中option的转换为数组,并根据option text的值,设置选中,并刷新
最新推荐文章于 2024-07-08 02:52:40 发布