0
文本區域的代碼。如何在文本框中突出顯示文字?
<div>
<textarea id="ta" onpaste="functionFind(event)"></textarea>
</div>
將執行
function functionFind(pasteEvent)
{
var textareacont = (pasteEvent.originalEvent || pasteEvent).clipboardData.getData("text/html");
var tofindword = prompt("Enter the word to find");
if(textareacont.includes(tofindword))
{
//What code do I write here so that all the word that matches "tofindword" gets highlighted in the same textbox only
}
}
一旦我們的東西粘貼到文本框,所有匹配的話應該只在同一個文本框獲得突出的功能將被執行的功能。
我不認爲你將能夠突出顯示文本框的多個部分。你也無法做任何事情,而不是選擇一段文字。如果要突出顯示多個選擇,則最好使用DIV作爲文本並使用HTML操作來添加高亮,例如以某種樣式在'span'中打包匹配。 – musefan