Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript tinyMCE键向上直到第一个<;p>;_Javascript_Jquery_Html_Tinymce - Fatal编程技术网

Javascript tinyMCE键向上直到第一个<;p>;

Javascript tinyMCE键向上直到第一个<;p>;,javascript,jquery,html,tinymce,Javascript,Jquery,Html,Tinymce,我试图实时捕获用户在.content文本区域中输入的内容,并将其粘贴到.intro。我试过了,但没有效果 //所有这些都与tinymce有关,因为我使用tinymce作为富文本编辑器,用于具有.tiny_editor类的文本框 //$(".content").live("keyup", function(e) { $(".content").keyup(function(e) { //The keyup never does its thing var stt=$(this).val()

我试图实时捕获用户在
.content
文本区域中输入的内容,并将其粘贴到
.intro
。我试过了,但没有效果

//所有这些都与tinymce有关,因为我使用tinymce作为富文本编辑器,用于具有
.tiny_editor
类的文本框

//$(".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);
});
然后,我还需要将其限制为
.content
文本区域中第一个
的内容

  • .content
    textarea
    ,用户在其中写入文本

    <textarea name="content" class="tinymce content">
       <p>first paragraph</p>
       <p>second paragraph</p>
       <p>third paragraph</p>
    </textarea>
    
有什么想法吗


在这种情况下,如果用户选择在第一段中,则必须检查每个按键事件

在tinymce init中,您需要添加如下设置参数。代码如下:

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隐藏了textare,并为内容使用了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);
      // }
   });

},
...

在这种情况下,如果用户选择在第一段中,则必须检查每个按键事件

在tinymce init中,您需要添加如下设置参数。代码如下:

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隐藏了textare,并为内容使用了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);
      // }
   });

},
...

什么是主文本框条目?您需要有点清楚(演示页面或小提琴在这里是一件好事)是否有一个特殊的时间点,当生成的textarea内容不再更改时?但是您要求停止更改该内容。您是否要求代码获取第一段的内容?已解决:请参阅我编辑的fiddle:(您可能需要在firebug中按下脚本选项卡的播放按钮,fiddle网站似乎有问题)。只是想让你知道存在一个特殊的tinymce fiddle站点:fiddle或tinymce fiddle在大多数情况下都有帮助(第一个用来理解问题,第二个用来展示解决方案)主文本框条目是什么?您需要有点清楚(演示页面或小提琴在这里是一件好事)是否有一个特殊的时间点,当生成的textarea内容不再更改时?但是您要求停止更改该内容。您是否要求代码获取第一段的内容?已解决:请参阅我编辑的fiddle:(您可能需要在firebug中按下脚本选项卡的播放按钮,fiddle网站似乎有问题)。只是想让你知道存在一个特殊的tinymce fiddle站点:fiddle或tinymce fiddle在大多数情况下都有帮助(第一个用来理解问题,第二个用来展示解决方案)只是一个注释-你最初的javascript不起作用的原因是因为tinymce在
之后创建了一个
,这就是内容所在。在我看来,您想要的是在两个
系统之间复制数据,实际上。。。我刚刚发现(firebug的帮助),刚刚看到这篇文章。。。但是仍然不知道如何告诉它从
.content
复制到
.intro
我也不太确定-我想你必须调用父窗口中的一个函数,它可以将数据发送到另一个iframe。以前从未这样做过,但我认为这可能只是一个注释-您最初使用的javascript不起作用的原因是因为tinyMCE在
之后创建了一个
,这就是内容所在。在我看来,您想要的是在两个
系统之间复制数据,实际上。。。我刚刚发现(firebug的帮助),刚刚看到这篇文章。。。但是仍然不知道如何告诉它从
.content
复制到
.intro
我也不太确定-我想你必须调用父窗口中的一个函数,它可以将数据发送到另一个iframe。以前从未做过,但我想这是可能的