gpt4 book ai didi

javascript - 在javascript中更改所选文本的字体样式

转载 作者:太空宇宙 更新时间:2023-11-04 13:15:35 25 4
gpt4 key购买 nike

我正在使用没有任何库的 javascript。现在我只想更改文本区域选定文本的字体样式。我使用以下函数提取了选择文本。谁能帮忙??

function ShowSelectionInsideTextarea(editor){

var textComponent = document.getElementById(editor);
var selectedText;
// IE version
if (document.selection != undefined)
{
textComponent.focus();
var sel = document.selection.createRange();
selectedText = sel.text;
}
// Mozilla version
else if (textComponent.selectionStart != undefined)
{
var startPos = textComponent.selectionStart;
var endPos = textComponent.selectionEnd;
selectedText = textComponent.value.substring(startPos, endPos)
}

console.log(selectedText);
}

最佳答案

怎么样

console.log(selectedText.fontsize(100)) ,更多信息请引用 docs

关于javascript - 在javascript中更改所选文本的字体样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27312928/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com