-
有办法为首行的特定文字开头添加自定义属性吗
2024-11-12 22:36css + js 试试
[data-type="NodeParagraph"].custom { border: 1px solid #FFFFFF; box-shadow: rgba(0, 0, 0, .2) 0 3px 5px -1px, rgba(0, 0, 0, .14) 0 6px 10px 0, rgba(0, 0, 0, .12) 0 1px 18px 0; box-sizing: border-box; padding: 10px; border-radius: 10px; margin: 0px 0px 20px 0px; }
function applyTagClass() { var paragraphs = document.querySelectorAll('[data-type="NodeParagraph"]'); paragraphs.forEach(function(para) { var editableDiv = para.querySelector('[contenteditable="true"]'); if (editableDiv && editableDiv.textContent.trim().startsWith('tags::')) { para.classList.add('custom'); } else { para.classList.remove('custom'); } }); } document.addEventListener('DOMContentLoaded', applyTagClass); var observer = new MutationObserver(applyTagClass); observer.observe(document.body, { childList: true, subtree: true });