1

ユーザーが入力したものをリアルタイムでキャプチャして、.content textareaに貼り付けようとしてい.introます。私はそのように試しましたが、効果はありませんでした

.tiny_editor// これはすべて tinymce に関連しています。クラスを持つテキスト ボックスのリッチ テキスト エディターとして tinyMCE を使用しているためです。

//$(".content").live("keyup", function(e) {
$(".content").keyup(function(e) { //The keyup never does its thing
    var stt=$(this).val();
    console.log('content : '+stt);
    $(".intro").text(stt);
});

<p>次に、最初のコンテンツで制限する必要もあります.content textarea

  • .content textarea、ユーザーがテキストを書く場所

    <textarea name="content" class="tinymce content">
       <p>first paragraph</p>
       <p>second paragraph</p>
       <p>third paragraph</p>
    </textarea>
    
  • これが自動的に挿入された場所です。first<p></p>fromの間のコンテンツ.content

    <textarea name="content" class="tinymce intro">
       <p>first paragraph</p>
    </textarea>
    

何か案は?

http://jsfiddle.net/xEzAq/2/

4

1 に答える 1

1

この場合、ユーザー選択が最初の段落内にある場合は、すべてのキーダウン イベントをチェックする必要があります。

tinymce init で、次のように setup パラメータを追加する必要があります。コードは次のとおりです。

setup : function(ed) {

  ed.onKeydown.add(function(ed, evt) {
    var node = ed.selection.getNode();
    while (node)
    {
        if (node.nodeName == 'BODY') { node = 0; break; }
        if (node.nodeName !== 'P')    { node = node.parentNode;}
        else { break; }
    }
    if (!node) return;
    var first_node_active = $(ed.getBody()).find('p:first').get(0) == node;
    // prevent insertion of content
    if (first_node_active){
        e.preventDefault();
        e.stopPropagation();
        return false;
    }
  });

},
...

更新: なるほど。実際、tinymce はテキストを非表示にし、コンテンツに contenteditable iframe を使用します。問題を解決する最も簡単な方法は、setup tinymce 構成パラメーターを使用することです。

tinyMCE.init({

  mode: 'exact',
  elements: 'content',
  ...
  setup : function(ed) {
   // handler to catch keyup events
   ed.onKeyup.add(function(ed, evt) {

      // get html content of first paragraph in the editor
      var first_node_html = $(ed.getBody()).find('p:first').html();

      // copythe html content into the textarea '.intro'
      $('.intro').text(first_node_html);

      // if intro is a tinymce editor too you will need some other code
      // here it is
      //
      // // check if intro exists as tinymce editor and make sure we are not editing in it at the moment (copying makes no sense then)
      // if (ed2 = tinymce.get('intro') && ed.id != ed2.id){
      //    ed2.setContent(first_node_html);
      // }
   });

},
...
于 2012-06-19T13:08:00.620 に答える