質問

しています。って取り組まなければならないが、今や大ブームとなったテレビアニメに爆発する.ここでの私の要件:
私は外部ツールバーの(ませんのゆい)のエディタを使いたいの挿入するHTMLタグです。は、ユーザーのクリックすることができ、ツールバーの後には数え上げればきりがないが発生する恐れがある:

  1. が生じた場合は選択テキストこのテキストがに包まれたHTMLタグ
  2. であれば、選択したテキスト、空のHTMLタグが挿入され、エディタ
  3. にかかわらずシナリオでは、カーソルを置かなければならな内部に新しい要素をする場合には、このようなユーザの文字でに存在する新しい要素

また、機能性と似ていることを押す"B"または"U"ボタンをエディタのツールバー(現しているところをこのエディタでもなく)).で保存しました。これまで私のことを1または2ない3.ステップ3は非常に重要なので、ユーザ体験を大きく失う。ズっぽい大人な雰囲気をご支援を実施します。以下は簡易版の方法を実行するの挿入(かに挿入部、簡単化のために).ます。_oEditor-地方のインスタンスゆいエディタ:

this._insertElement = function() {
var sSelection = this._oEditor._getSelection(); // Attempt to get selected text from the editor
if (sSelection == '') sSelection = ' '; // If nothing was selected, insert a non-breaking space

var sNewElt = '<div>' + sSelection + '</div>';

this._oEditor.execCommand('inserthtml', sNewElt);

this._oEditor.focus(); // This gives the editor focus, but places cursor in the beginning!
}

何でそうなる位置にカーソルを右す。でも可能ですか?また、より良い方法を実行するこっています。感謝です。

役に立ちましたか?

解決

をここで完全なソリューション:

this._insertElement = function() {
   var sSelection = this._oEditor._getSelection(); 
  if (sSelection == '') sSelection = ' '; 

  var sNewElt = '<div>' + sSelection + '</div>';

  this._oEditor.execCommand('inserthtml', sNewElt);

  var pos = 1000; //pos determines where to place the cursor. if greater than the length of characters, it will place at the end.
  if(this._oEditor.createTextRange) { //IE Specific code
        var range = this._oEditor.createTextRange();   
        range.move("character", pos);   
        range.select();   
    } else if(this._oEditor.selectionStart) {  //Works with Firefox and other browsers 

        this._oEditor.focus();   
        this._oEditor.setSelectionRange(pos, pos);   
  }  
  this._oEditor.focus(); 
}

他のヒント

カーソルを置くと、異なるブラウザのためのさまざまな方法が必要です。 IEを使用すると、Mozillaで、 TextRangeののオブジェクトを作成したいと思いますあなたは選択のオブジェクト、WebKitの/サファリnoreferrer"> window.find()または

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top