前端框架 materialize
目标
可以手动根据option 设置选中
方法
// item 目标select
$(item).find('option[value='+YourOptinoValue+']').prop('selected', true);
$(item).material_select();
原理
关注 material_select 方法-原手册中有如下说明
浏览源码发现,此处activateOption 函数实现了根据selected的option 添加页面selected效果并scroll到此处
activateOption:源码截图
可以确定: 手动选中option 需要2步
- 原select+options中设定选中值
- 在渲染部分-重新初始化[初始化过程会根据原选中状态来渲染]
欢迎沟通