xm-select/docs/mds/XM03.md
2019-09-25 17:47:38 +08:00

48 lines
942 B
Markdown

## 默认选中
### 使用`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>
```
:::