2014-12-29 3 views
-4
1 Programmatically inserting text into a text box 
2 Setting the caret to the end. 
3 Making the caret visible (i.e. scroll the text box content) 
4 Select some of the text from last programmatically, 
5 **set the selected text visible.** (i.e. scroll the text box content) 

1,2,3,4를 할 수 있습니다. 그러나 나는 할 수 없다.이 문제는 IE9에서만 존재한다 +선택한 텍스트를 IE에서 볼 수 있도록 설정

어떤 해결책 ??

+0

작성한 코드를 제공 하시겠습니까? –

+1

숙제입니까? – Satpal

+0

그렇다면 무엇입니까? – Francisc

답변

1

setSelectionRange()가 IE에서 완전히 지원되지 않습니다.

Google 검색을 많이 수행 한 결과 아래 코드로 바뀌었고 저에게 효과적이었습니다.

function setSelection(field, start, charsTobeSelected) { 
    end = start + charsTobeSelected; 
    if (field.createTextRange) { 
     var selRange = field.createTextRange(); 
     selRange.collapse(true); 
     selRange.moveStart('character', start); 
     selRange.moveEnd('character', end); 
     selRange.select(); 
     field.focus(); 
    } else if (field.setSelectionRange) { 
     field.focus(); 
     field.setSelectionRange(start, end); 
    } else if (typeof field.selectionStart != 'undefined') { 
     field.selectionStart = start; 
     field.selectionEnd = end; 
     field.focus(); 
    } 
} 
관련 문제