有没有一种方法可以根据帖子内容在css或sass中添加样式?
答案 0 :(得分:0)
我正在使用 https://github.com/jessegavin/jQuery-Chord-Transposer
某些原因阻止了我刚刚添加的代码的运行。
var textProp = 'textContent' in document ? 'textContent' : 'innerText';
// directly converting the found 'a' elements into an Array,
// then iterating over that array with Array.prototype.forEach():
[].slice.call(document.querySelectorAll('span.c'), 0).forEach(function(aEl) {
// if the text of the aEl Node contains the text 'link1':
if (aEl[textProp].indexOf('Am') > -1) {
// we update its style:
aEl.style.fontSize = '2em';
aEl.className = 'c foo';
}
});
答案 1 :(得分:-1)
我建议使用一薄层JS将CSS类添加到CSS可以检查的父元素中。
例如,如果某帖子中包含带有“ memes”的.category元素,则以下代码使文本变为红色
例如
<!DOCTYPE html>
<html>
<head>
<style>
.post.memes {
color: 'red'
}
</style>
</head>
<body>
<article class="post">
<p class="category">memes</p>
<p class="content">Lorem ipsum</p>
</article>
<script>
const postElement = document.querySelector('.post');
if (postElement) {
const category = postElement.querySelector('.category');
if (category && category.innerHTML == 'memes') {
postElement.classList.add('memes');
}
}
</script>
</body>
</html>