xm-select/docs/mds/XM03.md

48 lines
920 B
Markdown
Raw Normal View History

2019-11-19 20:13:50 +08:00
## 默认选中
### 使用`selected`属性
:::demo 当然`selected`是选中, `disabled`是禁用
```html
<div id="demo2" class="xm-select-demo"></div>
<script>
var demo2 = xmSelect.render({
el: '#demo2',
data: [
{name: '水果', value: 1, selected: true, disabled: true},
{name: '蔬菜', value: 2, selected: true},
{name: '桌子', value: 3, disabled: true},
{name: '北京', value: 4},
]
})
</script>
```
:::
### 使用initValue进行初始化
:::demo `initValue`的优先级大于选项中的`selected`
```html
<div id="demo1" class="xm-select-demo"></div>
<script>
var demo5 = xmSelect.render({
el: '#demo1',
initValue: [4],
data: [
{name: '水果', value: 1, selected: true, disabled: true},
{name: '蔬菜', value: 2, selected: true},
{name: '桌子', value: 3, disabled: true},
{name: '北京', value: 4},
]
})
</script>
```
:::