为动态加载的新元素添加tinymce

时间:2013-06-10 19:45:49

标签: tinymce

我的页面有5个div,可由Tinymce内联编辑器编辑。通过点击一个按钮(动态地),我得到了Jquery的和平,其中有5个新的。但是当然新的不受Tinymce的影响,因为init已经加载了......我怎么能设法为新的div激活tinymce?

我的HTML:

<div id=\"billetdroit\">
            <div id=\"divtitre\"><h1 class=\"editable\">blablabla</h1></div>
        <div class=\"editable\" id=\"tiny_01\">blablabla2</div>
        </div>
<div id=\"billetdroit\">
                <div id=\"divtitre\"><h1 class=\"editable\">blablabla</h1></div>
            <div class=\"editable\" id=\"tiny_02\">blablabla2</div>
            </div>
<div id=\"billetdroit\">
                <div id=\"divtitre\"><h1 class=\"editable\">blablabla</h1></div>
            <div class=\"editable\" id=\"tiny_03\">blablabla2</div>
            </div>

...
...

还有一个按钮:当你点击时,它会显示另外5个div“billetdroit”dynamicaly

我的tinymce init:

tinymce.init({
                    selector: "textarea",
                    language: 'fr_FR',
                    image_advtab: true,
                    menubar:false,
                    forced_root_block: false,
                    plugins: ["link","code","media","image","textcolor", "emoticons"],
                    toolbar: "bold italic forecolor backcolor alignleft aligncenter alignright alignjustify link unlink image media emoticons"
                 });
                 tinymce.init({
                    selector: "h1.editable",
                    language: 'fr_FR',
                    inline: true,
                    toolbar: "undo redo",
                    menubar: false
                });

                tinymce.init({
                    selector: "div.editable",
                    language: 'fr_FR',
                    image_advtab: true,
                    menubar:false,
                    inline: true,
                    forced_root_block: false,
                    plugins: ["link","code","media","image","textcolor", "emoticons"],
                    toolbar: "bold italic forecolor backcolor alignleft aligncenter alignright alignjustify link unlink image media emoticons"
                });

任何解决方案? 感谢

编辑:

我试过了:

$(document).ready(function() {

    var track_click = 1; //track user click on "load more" button, righ now it is 0 click

    var total_pages = Globals.total_pages;

//    $('#results').load("loadmore.php", {'page':track_click}, function() {track_click++;}); //initial data to load


    $(".load_more").click(function (e) { //user clicks on button

        $(this).hide(); //hide load more button on click
        $('.animation_image').show(); //show loading image

        if(track_click <= total_pages) //user click number is still less than total pages
        {
            //post page number and load returned data into result element
            $.post('loadmore.php',{'page': track_click}, function(data) {

                $(".load_more").show(); //bring back load more button

                $("#results").append(data); //append data received from server

                //scroll page smoothly to button id
                $("html, body").animate({scrollTop: $("#load_more_button").offset().top}, 500);

                //hide loading image
                $('.animation_image').hide(); //hide loading image once data is received

                track_click++; //user click increment on load button

            }).fail(function(xhr, ajaxOptions, thrownError) { //any errors?
                alert(thrownError); //alert with HTTP error
                $(".load_more").show(); //bring back load more button
                $('.animation_image').hide(); //hide loading image once data is received
            });


            if(track_click >= total_pages-1) //compare user click with page number
            {
                //reached end of the page yet? disable load button
                $(".load_more").attr("disabled", "disabled");
            }
         }
         $.getScript('include/tinymce/tinymce.min.js', function() {
            tinymce.init({
                    selector: "textarea",
                    language: 'fr_FR',
                    image_advtab: true,
                    menubar:false,
                    forced_root_block: false,
                    plugins: ["link","code","media","image","textcolor", "emoticons"],
                    toolbar: "bold italic forecolor backcolor alignleft aligncenter alignright alignjustify link unlink image media emoticons"
                 });
                 tinymce.init({
                    selector: "h1.editable",
                    language: 'fr_FR',
                    inline: true,
                    toolbar: "undo redo",
                    menubar: false
                });

                tinymce.init({
                    selector: "div.editable",
                    language: 'fr_FR',
                    image_advtab: true,
                    menubar:false,
                    inline: true,
                    forced_root_block: false,
                    plugins: ["link","code","media","image","textcolor", "emoticons"],
                    toolbar: "bold italic forecolor backcolor alignleft aligncenter alignright alignjustify link unlink image media emoticons"
                });
            });

        });
});

但没有成功......

1 个答案:

答案 0 :(得分:0)

有一种简单的方法来启动tinymce编辑器:

tinyMCE.execCommand("mceAddControl", false, 'your_div_id');