vue操作select获取option值方式

vue操作select获取option值

如何实时的获取你选中的值 只用@change件事

@change=”changeCategoryList($event)” 动态传递参数

vue操作select获取option的value值

示例

  <div id="app">
        <select name="topicCategoryId" class="article-title" id="category" @change="changeCategoryList($event)"  style="width: 180px;">
                <option  v-for="(category,index) in categoryList" v-bind:value="category.id">{{category.categoryTitle}}</option>
         </select>
   </div
  data:{
        categoryList:[{id:1,categoryTitle:"Java面试"},{id:2,categoryTitle:"Web开发"},
        {id:3,categoryTitle:"设计系统"},{id:4,categoryTitle:"框架服务"}]
     },
                
  methods: {
         changeCategoryList(event){
            console.log(event);
            var selectIndex =event.target.selectedIndex;//选中的第几个option元素 从0开始
            var options = event.target.options;//代表option组合
            
            options[selectIndex].innerHTML  //选择的值 // categoryTitle
            event.target.value;  //绑定的value值  //v-bind:value="category.id"
                                   
            console.log("options[selectIndex].innerHTML=="+options[selectIndex].innerHTML);
            console.log("event.target.value=="+event.target.value);
        }
       }

总结

以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。

来源链接:https://www.jb51.net/javascript/335015jo3.htm

© 版权声明
THE END
支持一下吧
点赞14 分享
评论 抢沙发
头像
请文明发言!
提交
头像

昵称

取消
昵称表情代码快捷回复

    暂无评论内容