[英]wrap selected text inside div in stars vuejs
大家好,我正在嘗試將所選文本包裝在 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)
}
這應該有助於查找和替換文本: Find and Replace for an Textarea
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.