2012-11-15 3 views
3

나는 다음과 같은 DIV있다. 그 때문에 나는 다음의 ChangeListener이 : 나는 document.execCommand()를 사용하려고선택하지 않고 execCommand를 사용 하시겠습니까? 단어 <strong>굵은</strong>마다 사용자가 입력하게 볼의 나는 특정 금액을 만들고 싶어이 사업부 내부</p> <pre><code><div contenteditable="true" unselectable="off" id="foo"> </code></pre> <p>:

$('#foo').live('focus', function() { 
    before = $(this).html(); 
}).live('blur keyup paste', function() { 
    if (before != $(this).html()) { $(this).trigger('change'); } 
}); 

$('#foo').live('change', function() { 
    // make certain words bold 
    document.execCommand ('bold', false, null); // doesn't work 
}); 

을하지만 난 굵은을 할 텍스트를 선택하는 경우에만 작동합니다. 그러나 사용자가 굵게이어야하는 단어를 모르기 때문에 텍스트를 선택하고 싶지 않습니다.

답변

1

먼저 execCommand를 사용하여 굵은 텍스트를 선택하지 않아도됩니다.

정확히 무엇을하고 있는지 이해할 수 없지만 굵은 글씨체로 만들고 싶은 단어를 알고 있다면 js를 사용하여 편집기 html에서 <strong>your word</strong>으로 바꿉니다.

+0

내 테스트에서 실행 취소/다시 실행을 실행 중지합니다. – bumfo