uniapp获取复选框的值
文章描述:
uniapp如何获取复选框的值
template
<template>
<view>
<checkbox-group @change="selectCk">
<view>
<label>爱好:</label>
<label>
<checkbox value="看书" /><text>看书</text>
<checkbox value="打游戏" /><text>打游戏</text>
<checkbox value="爬山" /><text>爬山</text>
<checkbox value="游泳" /><text>游泳</text>
</label>
</view>
</checkbox-group>
<button type="default" @tap="submit">提交</button>
</view>
</template>
script
export default {
data() {
return {
namesel:'',
};
},
onLoad() {
},
methods: {
selectCk:function(e){
console.log('eee',e)
this.namesel=e.detail.value;
this.namesel=this.namesel.join(",");
console.log('复选框的值:',this.namesel);
},
submit(e) {
if (this.namesel== '' ||this.namesel==null||this.namesel==undefined) {
console.log('请勾选选项');
return false;
}
var namesel=this.namesel;
console.log(namesel);
},
}
}
发布时间:2021/11/09
发表评论