0
点赞
收藏
分享

微信扫一扫

div选中样式

回望这一段人生 2022-03-30 阅读 69
前端cssvue

div点击时:focus等无法实现选中样式,可以使用动态class实现

html部分:

@click="handleView($event)"
    

CSS部分:

.active{
    color: #fff;
    border-right:3px solid;
    background-color: #f0c195;
}

method部分:

methods:{
      handleView: function (e) {
         let currentClick = e.target;//当前点击
         if( this.lastClick !== ""){//上次点击
             this.lastClick.removeAttribute("class")
         }
         this.lastClick = currentClick;
         currentClick.setAttribute("class","active");//添加class属性
    }
举报

相关推荐

0 条评论