动态绑定任务div class:根据reminder属性添加提醒样式
Task 1
Task 2
Task 3
可以使用JavaScript代码动态绑定每个任务div的class:
const tasks = document.querySelectorAll('.task');
tasks.forEach((task) => {
const isReminder = task.getAttribute('data-reminder') === 'true';
if (isReminder) {
task.classList.add('reminder');
}
});
这段代码会遍历每个任务div,判断其data-reminder属性是否为true,如果是,则为该任务div添加一个名为reminder的class。这样,所有reminder属性为true的任务div就会有一个相同的class了。
原文地址: https://www.cveoy.top/t/topic/mFEm 著作权归作者所有。请勿转载和采集!