当前位置: 代码网 > it编程>编程语言>Javascript > vue操作select获取option值方式

vue操作select获取option值方式

2025年02月13日 Javascript 我要评论
vue操作select获取option值如何实时的获取你选中的值 只用@change件事@change="changecategorylist($event)" 动态传递参数vue

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);
        }
       }

总结

以上为个人经验,希望能给大家一个参考,也希望大家多多支持代码网。

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com