gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-05 08:00:51 43 4
gpt4 key购买 nike

我的页面加载了 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”

我的 tinymce 初始化:

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"
});
});

});
});

但是没有成功...

最佳答案

有一个简单的方法来初始化 tinymce 编辑器:

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

关于tinymce - 为动态加载的新元素添加 tinymce,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17031589/

43 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com