select同时获取value和label的值


Element ui 框架型

<el-select v-model="sketchID" autocomplete="off" @@change="setEmpty" id="sketchID2">
                            <el-option
                                    v-for="item in sketchOptions"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value">
                            </el-option>
                        </el-select>
setEmpty:function (data) {
                var _this = this
                console.log('data',data)
                let obj = {};
                obj = this.sketchOptions.find((item)=>{//这里的sketchOptions就是上面遍历的数据源
                    return item.value === data;//筛选出匹配数据
                })
                console.log('obj.label',obj.label);
          console.log('obj.value',obj.value);
},
sketchOptions: [{
    value: '1',
    label: '安装位置不正确'
}, {
    value: '2',
    label: '空置房'
}],

 

原生型:

<select  autocomplete="off" @change="setEmpty" id="sketchID">
                            <option
                                    v-for="item in sketchOptions"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value">
                            </option>
</select>
setEmpty:function () {
                var _this = thisvar s = $("#sketchID").find("option:selected").text(); 
          console.log(s
.text())
          console.log(s.value())

}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM