点击tab动态添加类名
时间: 2023-08-05 16:04:41 浏览: 177
动态添加tabcontrol 和动态添加按钮
5星 · 资源好评率100%
可以使用以下代码来实现点击tab时动态添加类名:
```javascript
$('.tab').click(function() {
$(this).addClass('current').siblings().removeClass('current');
});
```
这段代码使用了jQuery库,当点击.tab元素时,它会给当前元素添加current类,并移除其他兄弟元素的current类。这样就可以实现点击tab时动态添加类名。\[1\]
#### 引用[.reference_title]
- *1* [点击添加类名—js实现鼠标点击一个div删除另一个div的class中的其中一个类名,再点击一下又添加上](https://blog.csdn.net/weixin_44711440/article/details/105511661)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item]
- *2* [vue动态添加类名方法(实现tab切换效果或导航选中效果)](https://blog.csdn.net/qq_24441205/article/details/128653670)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item]
- *3* [vue Tab效果,动态添加类,移除兄弟类](https://blog.csdn.net/qq_34936893/article/details/125909571)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文