私は execCommand で問題を抱えています (完全に) ので、あなたは非常に感謝しています - 私は間違ったツリーを吠えていることは間違いありませんが、.....とにかく.
私はこのようなdivを持っています
<div class="editable" id="editor" contenteditable="true">
<2>Some text in here</h2> blah blah blah ...
</div>
それは「編集可能」です。つまりdocument.designMode = 'on';
、この「状態」をフォーカスします。ぼかしの場合は次のように変わりますdocument.designMode = 'off';
「テストボタン」があります
<input type="button" id="bold" value="Bold">
「クリック」すると、「強調表示されたテキスト」が太字になるため、execCommand
これまでのところ、次のようなものがあります。
function getSelected() {
if(window.getSelection) { return window.getSelection(); }
else if(document.getSelection) { return document.getSelection(); }
else {
var selection = document.selection && document.selection.createRange();
if(selection.text) { return selection.text; }
return false;
}
return false;
}
$('#bold').click(function(){
var selection = getSelected();
alert(selection);
});
アラート (太字クリック) により、強調表示/選択されたテキストが表示されますが、「太字にする」方法がわかりません。innerHTML か何かにアクセスする必要があると思いますか?
よろしくお願いします - 事前に感謝します。ああ、i-frame も textarea も使いたくない