将选中的文本包装在星形vuejs中的div中



大家好,我正在尝试将所选文本包装在2颗星之间的文本区域中例如,条目为vuejs=>**vuejs**。尽管我不知道如何让选中的文本只用星星包裹。

//this is my text area object
<textarea class="outline-none w-100" id="textAreaExample3" rows="4" placeholder="taper 
votre texte" ></textarea>
//this is the method that gets triggered on a button click when the text gets selected
makeSelectedTextBold(){
let text = document.getElementById('question').innerText;
// selected text
let selection = window.getSelection().anchorNode.data;
console.log(selection)
// wrap text to be shown on button click (I couldn't figure this out can someone help me)

},

这将有助于HTML:

<button id="button" onclick="makeSelectedTextBold()">here<button>
<textarea class="outline-none w-100" id="textAreaExample3" rows="4" placeholder="taper votre texte" ></textarea>

这将有助于JS:

document.getElementById("button").addEventListener("click");
function makeSelectedTextBold(){
let text = document.getElementById("textAreaExample3").value;
console.log("text:" + text)
let selection = window.getSelection();
console.log("selection:" + selection)
}    

这将有助于查找和替换文本:查找和替换文本区域

我不太明白你想做什么。把文本区域中的所有文本都用粗体显示,还是把控制台日志中的文本用粗体显示?

最新更新