2009-10-29 2 views

답변

34

저는 약간 다른 질문을했습니다. 다음 방금 하이라이트 자체를 삭제하려면

function deleteSelection() { 
    if (window.getSelection) { 
     // Mozilla 
     var selection = window.getSelection(); 
     if (selection.rangeCount > 0) { 
      window.getSelection().deleteFromDocument(); 
      window.getSelection().removeAllRanges(); 
     } 
    } else if (document.selection) { 
     // Internet Explorer 
     var ranges = document.selection.createRangeCollection(); 
     for (var i = 0; i < ranges.length; i++) { 
      ranges[i].text = ""; 
     } 
    } 
} 

, 그리고 텍스트를 제거하지 강조되고 : 난 당신이 사용할 수있는 경우 문서에서 선택한 텍스트를 삭제하는 방법을 알고 싶은 생각 트릭을해야합니다 :

function clearSelection() { 
    if (window.getSelection) { 
     window.getSelection().removeAllRanges(); 
    } else if (document.selection) { 
     document.selection.empty(); 
    } 
} 
+1

실제로 표시된 하이라이트를 제거하고 싶습니다. – thedp

+0

정말 고마워요 :) – thedp

1

IE 4 및 이전 Netscape는이 작업을 수행하는 데 사용한 방법이 ... 더 이상 적절하지 않으며 지원되지 않습니다.

JavaScript를 사용하여 객체에 초점을 맞춘 다음 객체에서 멀리 클릭하는 것과 같이 blur()를 사용하는 것이 가장 좋습니다.

document.getElementById("someObject").focus(); 
document.getElementById("someObject").blur();