여기에 우리가 다시 간다. 나는 IE 충돌에서 createRange() 사용
내가 코드를 가지고 ...이 문제에 대한 해결책을 하루 종일 찾아 봤는데 :var formatString = function(t,style){
var el = $(t);
var pre;
var start;
var end;
var len;
var replace;
switch(style){
case 'italic':
pre = '[em]';
break;
case 'bold':
pre = '[b]';
break;
case 'paragraph':
pre = '[p]';
break;
}
if(document.selection){
el.focus();
var sel = document.selection.createRange();
// Finally replace the value of the selected text with this new replacement one
sel.text = pre + sel.text + pre.replace(/(\[)/,'[/');
} else {
len = el.val().length;
start = t.selectionStart;
end = t.selectionEnd;
sel = el.val().substring(start, end);
replace = pre + sel + pre.replace(/(\[)/,'[/');
el.val(el.val().substring(0,start) + replace + el.val().substring(end,len));
}
}
내가 그냥 텍스트에 일부 형식화하는 추가하는 간단한 WYSIWYG을 만드는 일을 해요 분명히 올바른 html 태그를 표시하도록 처리됩니다. 모두 IE를 제외한 모든 브라우저에서 잘 작동합니다.
사랑하는 IE가 텍스트 영역 바깥을 클릭했을 때 선택된 텍스트를 선택 취소하는 문제가 있습니다. 그리고 이로 인해 sel.text 객체에 텍스트가 표시되지 않습니다.
나는 다음과 같은 기능을 실행 :이 다른 스레드가 그냥 저를 인도 같은 경우
<button onclick="formatString($('#textid')[0],'italic')">Italic</button>
버튼 다른 브라우저 출력을
'the italic text' // output the [em]italic[/em] text - when italic is selected
IE output 'the [em][/em]italic text'
을 클릭하면, 말 그대로 내가 가지고있는 200 개 이상의 스레드를 읽었으며이 문제를 지적하지 않았습니다.