首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么tinyMCE.editors不能在wordpress的tinyMCE上运行?

为什么tinyMCE.editors不能在wordpress的tinyMCE上运行?
EN

Stack Overflow用户
提问于 2014-07-20 15:03:15
回答 1查看 82关注 0票数 0
代码语言:javascript
复制
<?php 
/*
Plugin Name: Taggr
Plugin URI: http://example.com/wordpress-plugins/my-plugin
Description: Premium plugin for image and photo tagging
Version: 1.0
Author: Tee Kai Yang
Author URI: http://wrox.com
License: GPLv2
*/


add_action('init', 'register_tagging_post');

//create taggr post type

 function register_tagging_post(){

       $tagging_args = array(
           'public' => true,
           'supports' => array(
               'title',
               'thumbnail'

           ), 
           'query_var' => 'tagging',
           'rewrite' => array(
              'slug' => 'taggr',
              'with_front' => false
           ),
            'labels' => array(
            'name' => 'Taggr Albums',
            'singular_name' => 'Album',
            'add_new' => 'Add New Album',
            'add_new_item' => 'Add New Album',
            'edit_item' => 'Edit Album',
            'new_item' => 'New Album',
            'view_item' => 'View Album',
            'search_items' => 'Search Albums',
            'not_found' => 'No Albums Found',
            'not_found_in_trash' => 'No Albums Found In Trash'
        ),

        'menu_icon' => plugins_url() . '/taggr/images/PhotoAlbum.png',

        'menu_position' => 80, 

       );

       register_post_type('tagging', $tagging_args);


 }

    add_action( 'add_meta_boxes', 'taggr_create_meta' );
 function taggr_create_meta(){

     add_meta_box( 'taggrMeta', 'Upload and edit photos/images', 'taggr_meta_function', 'tagging', 'normal', 'high' );

     function taggr_meta_function(){


     ?>

       <?php wp_editor("Enter your text", "my_editor"); ?>

    <script>
    window.onload = function(){
        alert(tinyMCE.editors[0].getContent());
    }
    </script>

        <?php

    }


    }


?> 

上面是我的代码,我在metabox中创建了一个自定义帖子和一个tinyMCE文本编辑器。但是为什么在执行alert(tinyMCE.editors[0].getContent());代码行时,它不能工作,也不能显示编辑器的内容。firebug显示TypeError: tinyMCE.editors[0] is undefined的错误

EN

回答 1

Stack Overflow用户

发布于 2014-07-26 15:38:31

你可以提供你的编辑器文本区域的ID来获得编辑器的内容,你也应该获得保存的tinyMCE元的内容并将它设置为你的编辑器元素的文本,以显示之前保存的值。您可以使用以下代码作为参考,

代码语言:javascript
复制
<?php
function taggr_meta_function($post){
 $my_editor = get_post_meta($post->ID, 'my_editor', true);
 wp_editor( $my_editor, "my_editor", array( 'textarea_name' => "my_editor" ) );
?>
   <script>
    window.onload = function(){
        alert(tinyMCE.get('my_editor').getContent());
    }
   </script>
<?php } ?>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24848192

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档