Layui xm-select 赋值教程:使用 setValue 方法设置默认值
Layui xm-select 如何赋值:使用 'setValue' 方法设置默认值
使用 Layui 的 xm-select 组件,您可以通过 'setValue' 方法为下拉框设置初始值。
示例代码
// 初始化 xm-select
var xmSelect = xmSelect.render({
el: '#select',
data: [...],
});
// 设置初始值
xmSelect.setValue(['value1', 'value2']);
其中,'setValue' 方法的参数为一个数组,数组中的元素为需要选中的选项的值。
说明
- 'setValue' 方法会将下拉框中对应值的选项设置为选中状态。
- 如果您需要设置多个选项为选中状态,只需将所有选项的值添加到数组中即可。
注意事项
- 'setValue' 方法需要在 xm-select 初始化完成后调用。
- 确保您传入 'setValue' 方法的数组中包含的选项值在 'data' 属性中存在。
更多信息
请参考 Layui 的官方文档:https://www.layui.com/doc/modules/xmselect.html 获取更多关于 xm-select 的使用方法。
原文地址: https://www.cveoy.top/t/topic/mLNM 著作权归作者所有。请勿转载和采集!