它使整个文本加粗。我只想将选定的文本加粗(绝对没有 exec 命令)
let boldBtn = document.getElementById('Bold-Btn');
let boldClickListener = (event) =>
{
event.preventDefault();
let selection = window.getSelection();
let final = `<span class="text-bold">${selection.focusNode.textContent}</span>`;
selection.anchorNode.parentElement.innerHTML=final;
console.log(selection);
};
boldBtn.addEventListener('click',boldClickListener);
慕慕森
相关分类