点击当前标签给其添加class,兄弟标签class删除 然后获取当前点击元素的文字 演示地址: https://xibushijie.github.io/static/addClass.html <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>vue 点击当前元素添加class 去掉兄弟的class</title> <script src…
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>vue 点击当前元素添加class 去掉兄弟的class</title> <link rel="stylesheet&qu…
<div id="app"> <ul> <li v-for="(todo, index) in todos" v-on:click="addClass(index)" v-bind:class="{ blue:index==current}">{{ todo.text }}</li> </ul> </div> <script> new Vue(…
vue不同序号的元素添加不同的样式 一.总结 一句话总结: 在vue中设计一个样式的数据数组来遍历即可 <script> new Vue({ el:'#review_exam_part', data:{ exam_part_style:[ 'small-box exam_part_color_1', 'small-box exam_part_color_2', 'small-box exam_part_color_3', 'small-box exam_part_color_4', 'smal…
<style> .active { color: red; } </style> //html代码 <ul id="tab2"> <li><a href="http://www.cnblogs.com/index.html">首页</a></li> <li><a href="http://www.cnblogs.com/news.html">…
template  <ul>    <li v-for="(relation,index) in relations" v-bind:id="relation.id" v-bind:id="relation.id" v-bind:class="{checked:index==nowIndex}" v-on:click="relationClick(index)">     <i…
最近使用vue需要实现一个点餐选择商品规格的页面,需要通过vue动态的给被点击的元素添加class名字,使其变色,其他的删除class.如图: 开始在网上找了许多办法发现不是太好用,最后找到一个发现还是不错的,记录一下 html: <div class="weui-mask" id="guige"> <div class="guigeBox"> <p class="guigeTitle">{…
VUE中 html 中 <ul id="shoppingList" v-on:click="addClass($event)" class="iview-admin-draggable-list"> <li></li> </ul> 点击li时 js如下 addClass:function(e){ console.log(e.target); if(e.target.parentNode.classN…
首先 vue的点击事件 是用 @click = “clickfun()” 属性 在html中绑定的,在点击的函数中 添加$event 参数就可以比如<button @click = “clickfun($event)”>点击</button> methods: { clickfun(e) { // e.target 是你当前点击的元素 // e.currentTarget 是你绑定事件的元素 } },…
在Vue中,给当前元素添加类名移除兄弟元素类名的方法 今天在项目中需要做一个效果,点击对应的li改变当前的color,其他的li取消颜色,在jQuery中这很容易,由于之前已经引入了jQuery,所以直接想到了这个办法. 但是出于未知的原因,jQuery获取不到v-for出来的数据,根本找不到dom节点,所以不得不改变思路. 然后我想到了V-bind的方法.下面贴上步骤. 1.在data里面申明一个属性,默认值最好为数字类型,并且不得大于当前元素+所有兄弟元素的length,可以默认为0(第一个…