0
텍스트 영역의 코드입니다. 우리가 텍스트 상자에 무언가를 붙여 넣기와 일치하는 모든 단어는 같은 텍스트 상자에 강조 취득해야하면이 기능이 실행됩니다텍스트를 강조 표시하려면 어떻게해야합니까?
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>
<textarea id="ta" onpaste="functionFind(event)"></textarea>
</div>
기능.
텍스트 상자의 여러 섹션을 강조 표시 할 수 없을 것이라고 생각합니다. 또한 텍스트 섹션을 '선택'하는 것 외에는 아무 것도 할 수 없습니다. 여러 항목을 강조 표시하려면 텍스트에 DIV를 사용하고 HTML 조작을 사용하여 하이라이트를 추가하는 것이 가장 좋습니다 (예 : 특정 스타일의 'span'에 줄이 쳐지는 경우). – musefan