我是靠谱客的博主 重要鸡翅,这篇文章主要介绍如何获取dom内class的值,现在分享给大家,希望可以做个参考。

这次给大家带来如何获取dom内class的值,获取dom内class值的注意事项有哪些,下面就是实战案例,一起来看一下。

vue点击给dom添加class然后获取含有class的dom

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<p class="chose-ck" v-for="(item,index2) in colors" :key="index2" ref="chosebox"> <p>{{item.name}}</p> <dt v-for="(item2,index) in item.childsCurGoods" :key="item2.id" :class="index==iac[index2]?'check':''" :id="item2.id" :data-chosename="item.name" :data-choseidname="item2.name" :data-chose="item.id" :data-id="item2.id" @click="chek(index2,index)" > {{item2.name}} </dt> </p>js chek(index2, index) { this.iac[index2] = index this.iac = this.iac.concat([]); this.checkchose() }, checkchose:function(){ var chose=this var chosedom=chose.$refs.chosebox console.log(chosedom) for (var i=0;i<chosedom.length;i++) { var children=chosedom[i].children for (var j=0;j<children.length;j++) { if(children[j].className=="check") { console.log(children[j]) } } } }
登录后复制

点击过后获取到的dom打印

复制代码
1
if(children[j].className=="check")
登录后复制

加了判断为什么打印出来的dom是点击之前的dom

相信看了本文案例你已经掌握了方法,更多精彩请关注靠谱客其它相关文章!

推荐阅读:

做一个移动端微信公众号(附代码)

JS链式调用(附代码)

以上就是如何获取dom内class的值的详细内容,更多请关注靠谱客其它相关文章!

最后

以上就是重要鸡翅最近收集整理的关于如何获取dom内class的值的全部内容,更多相关如何获取dom内class内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(93)

评论列表共有 0 条评论

立即
投稿
返回
顶部