簡體   English   中英

更改所選文本Javascript的顏色

[英]Change color of a selected Text Javascript

當我單擊按鈕時,需要從文本區域中的選定文本更改文本顏色。

我的第一次嘗試:

document.getSelectedText(document.getElementById('test22')).style.color = '#0F0';

我的嘗試:

document.getSelectedText((test22.value).substring(test22.selectionStart, test22.selectionEnd)).style.color = '#0F0';

HTML代碼:

<textarea name="area1" cols="40" id="test22"></textarea>
<button onclick="test();">CLICK</button>

謝謝! ;)

無法在Textareas中進行設置,因為它們不是RTF編輯器。

您可以將contenteditable =“ true”標記與div結合使用,並在其中做魔術,就像在各處設置“ font”標記一樣。

您還可以使用https://www.tinymce.comhttp://ckeditor.com之類的東西。 兩者都是所見即所得的編輯器。 或在github上搜索任何輕型RTF編輯器。

也許您可以從中得到一些想法: http : //dipaksblogonline.blogspot.in/2014/11/javascript-text-selection-popover.html

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM