javascript - 如何创建添加角色 =“演示文稿”的脚本
问题描述
我想创建role="presentation"
动态添加到页面上所有图像的脚本,但我不知道为此使用什么类型的函数。图像是动态添加的,所以我不能手动添加。下面我上传我的源代码。
//.attachment-large(class that img has)
//.elementor-inner-section (class that the div with images has)
(()=>{ function AddRole() {
const imageHook = document.querySelectorAll(".attachment-large");
const boxHook = document.querySelector(".elementor-inner-section");
boxHook.forEach((box) => {
imageHook.setAttribute("style","role: presentation") });
} AddRole() })();
解决方案
role
是一个属性本身(以及style
)。所以你需要运行:
imageHook.setAttribute('role', 'presentation');
顺便说一句,运行它imageHook
必须足够,没有循环遍历boxHook
- 你似乎对此没有依赖性。
推荐阅读
- r - 更改图例形状以匹配绘图 (ggplot2)
- react-native - ScrollToLocation 在初始安装时不起作用
- sql - SAS proq sql 字符(存储为自 1960 年以来的天数)到日期
- bash - 如何将带有参数的命令发送到 GNU 并行?
- java - 从套接字创建 BufferedReader 时,如果连接失败,readLine() == null 会不会?
- asp.net-mvc - 发布我的 ASP.NET Core MVC 应用程序时,Entity Framework Migrations 选项显示错误
- puppeteer - 在专门调用的类之后不单击元素
- android - Android RecyclerView 和 ListView - 父视图滚动不足,ListView 隐藏
- docker - 如何在本地安装引用为 github.com 地址的 Golang 包
- c++ - 跨线程读取无符号整数时,c++ 位是否自动切换?