나는 firefox에서 열린 html 페이지에서 마우스를 사용하여 텍스트를 선택하고 javascript 함수를 사용하여 선택한 텍스트에 해당하는 range 객체를 만들거나 가져옵니다.DOM Range 개체의 텍스트를 어떻게 강조 할 수 있습니까?
userSelection =window.getSelection();
var rangeObject = getRangeObject(userSelection);
지금 내가,
var span = document.createElement("span");
rangeObject.surroundContents(span);
span.style.backgroundColor = "yellow";
음을 다음과 같이 그 일을하고있는 rangeobject.I에 해당되는 모든 텍스트를 강조하려면이 잘 만 rangeobject (시작점과 끝점)을 작동 같은 textnode에있다, 그것은 해당 text.Ex
<p>In this case,the text selected will be highlighted properly,
because the selected text lies under a single textnode</p>
을 강조하지만 rangeobject 하나 이상의 textnode, 그것은 작동하지 않는 properlay을 포함하는 경우, 그것은 단지 텍스트를 강조하는 첫 번째 textnode에 rangeobject에 해당되는 예
<p><h3>In this case</h3>, only the text inside the header(h3)
will be highlighted, not any text outside the header</p>
내가 할 수있는 방법 어떤 생각, 모든 텍스트를, 거짓말을하는 것은 범위가 단일 노드 또는 여러 노드에 있는지 관계없이 강조? 감사합니다 ....
가능한 복제본 : http://stackoverflow.com/questions/1622629/javascript-highlight-selected-range-button –