把<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'); }
相关文章推荐
- HTML中的<select>标签如何设置默认选中的选项
- HTML中的<select>标签如何设置默认选中的选项
- js javascript <select>根据value或text设置下拉列表的默认值
- HTML中的<select>标签如何设置默认选中的选项
- HTML中的<select>标签如何设置默认选中的选项
- HTML中的<select>标签如何设置默认选中的选项
- HTML中的<select>标签如何设置默认选中的选项
- <meta http-equiv="Content-Type" content="text/html; charset=gb2312">设置中文显示
- JQuery 通过option的text值设置选中项
- JS给<select>的<option>赋值&JS发异步请求获取后台列表
- <select> js中 设置选重
- <select>里动态添加option
- HighCharts趋势图动态设置Series数组(根据后台决定具体几个data), 并动态刷新数据
- JSP用到一个下拉框<select> 页面刷新后,保持选中的值
- <select>设置css height兼容性,兼容FF/IE/Safari/Chrome...
- js对<select><option>操作和jq的选择器
- <html:select>,<html:option>,<html:options>,<html:optionsCollection>标签使用
- 根据select中option的text或value来选中
- <s:textfield> 标签设置默认值
- <html:select>,<html:option>,<html:options>,<html:optionsCollection>标签使用