我做了一个自定义属性,我希望当开头检测到 tags::开头就自动添加我设置的那个自定义属性
相关帖子
-
onemo •付费者
css + 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 });
-
css + 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 });
1 回复 - 其他回帖
-
-
- 查看全部回帖