当前位置:网站首页>【JS给元素添加属性:setAttribute;classList.remove;classList.add;】
【JS给元素添加属性:setAttribute;classList.remove;classList.add;】
2022-07-01 01:00:00 【Min_Fox】
- 首先获取当前元素
html
<img id="zi" class="zi" src="/src/image/w.png">
js
const zi = document.getElementById("zi");
- 修改img元素的src属性
使用setAttribute来设置属性。
js
zi.setAttribute("src", this.key);
- 给元素添加class
使用classList.remove来删除 class、classList.add来新增class,可以用来修改样式。
js
// 删除class
zi.classList.remove("update-file-block");
// 增加class
zi.classList.add("update-file-none");
css
.update-file-block {
display: inline-block;
}
.update-file-none {
display: none !important;
}
边栏推荐
- 工作6年,来盘点一下职场人混迹职场的黄金法则
- 工作八年的程序员,却拿着毕业三年的工资,再不开窍就真晚了...
- TypeError: can‘t convert cuda:0 device type tensor to numpy. Use Tensor. cpu() to copy the tensor to
- Matlab farthest point sampling (FPS improved version)
- 物业怎么发短信通知给业主?
- 未来的 Web3会带来什么?
- DC學習筆記正式篇之零——綜述與基本流程介紹
- Strictmode analysis registration strictmode principle (4)
- neo4j安装、运行以及项目的构建和功能实现
- System. Csrebot for commandline
猜你喜欢

3dsmax plug-in development traversal node object and object acquisition and inode transformation matrix description

Compile and install oh my Zsh

45 year old programmer tells you: why do programmers want to change jobs? It's too true

Exploration and practice of "flow batch integration" in JD

Necessary tools for testing - postman practical tutorial

gin_ gorm

Institute of Microbiology, commonly used biochemical reactions in microbiological testing

Service grid ASM year end summary: how do end users use the service grid?

Introduction and principle analysis of cluster and LVS

个人博客搭建与美化
随机推荐
股票开户有哪些优惠活动?另外,手机开户安全么?
图灵奖得主LeCun指明AI未来的出路在于自主学习,这家公司已踏上征途
【栈】921. Minimum Add to Make Parentheses Valid
Unknown database connection database error
MFC TCP communication server client demo notes vs2019
Use of laravel carbon time processing class
3500字归纳总结:一名合格的软件测试工程师需要掌握的技能大全
Use strictmode strictmode principle (1)
【office办公-pdf篇】pdf合并与拆分让我们摆脱付费软件的功能限制好不好
45岁程序员告诉你:程序员为什么要跳槽,太真实...
Handsontable數據網格組件
php将二维数组元素转为键值对
Some items of OCR
为什么要搭建个人博客
qt5-MVC:数据可视化的层次揭秘
医疗HIS行业短信发送解决方案
【Qt5-基础篇_1】从0开始,德天老师和你一起学习——窗口简介
KS009基于SSH实现宠物管理系统
Strictmode analysis activity leakage -strictmode principle (3)
Last day of the second quarter