【发布时间】:2022-08-12 22:50:30
【问题描述】:
目标:更改 forEach 循环中元素的样式
问题:未应用样式
在我的循环中,如果我使用 console.log(element),我会得到正确的过滤元素列表。
运行这个工作,但我希望我的函数修改与我的过滤器匹配的每个元素:
let contentPreview = document.querySelectorAll(\'.o_last_message_preview\');
contentPreview[0].style.color = \'yellow\'
所有元素均已正确分配。
function changeNotificationColor() {
// Notification button that opens list of notifications
let notifyButton = document.querySelector(\'.dropdown-toggle.o-no-caret[title=\"Conversations\"]\');
notifyButton.addEventListener(\'click\', function () {
// List of notifications - each notification is contained in a .o_last_message_preview class
let contentPreview = document.querySelectorAll(\'.o_last_message_preview\');
contentPreview.forEach(function (element) { if (element.innerText.includes(\'Marine\')) {element.style.color = \'yellow\'}})
})
}
changeNotificationColor();
标签: javascript