Javascript 如何用tinyMCE 3动态创建tinyMCE
我正在使用Javascript 如何用tinyMCE 3动态创建tinyMCE,javascript,php,tinymce,Javascript,Php,Tinymce,我正在使用tinyMCE 3.9.3。这一页已经有三个字母了。当用户单击id为add\u line的超链接时,应显示一个新的tinyMCE,但由于某些原因,它仅显示一个文本区域。新文本区域的id格式为comment+int(例如,第一个新文本区域的id为comment4,第二个新文本区域的id为comment5)。 我试图将第一个新文本区域(comment4)静态转换为一个tinyMCE,但失败了 这是tinyMCE的初始值: tinyMCE.init({ //G
tinyMCE 3.9.3
。这一页已经有三个字母了。当用户单击id为add\u line
的超链接时,应显示一个新的tinyMCE,但由于某些原因,它仅显示一个文本区域。新文本区域的id格式为comment+int
(例如,第一个新文本区域的id为comment4
,第二个新文本区域的id为comment5
)。
我试图将第一个新文本区域(comment4
)静态转换为一个tinyMCE,但失败了
这是tinyMCE的初始值:
tinyMCE.init({
//General options
mode : "textareas",
language : "<?=$_SESSION['interface_lang'];?>",
valid_elements : '*[*]',
forced_root_block: false ,
theme : "advanced",
plugins: "style,table,template","bold,italic,underline,strikethrough,justifyleft,justifycenter,justifyright,justifyfull,bullist,numlist,outdent,indent,cut,copy,paste,undo,,redo,link,unlink,image,cleanup,help,code,hr,removeformat,formatselect,fontselect,fontsizeselect,styleselect,sub,sup,forecolor,backcolor,forecolorpicker,backcolorpicker,charmap,visualaid,anchor,newdocument,blockquote,separator",
theme_advanced_buttons1 : "formatselect,fontsizeselect,styleselect,|,bold,italic,underline,|,justifyleft,justifycenter,justifyright,justifyfull,|,cut,copy,paste,undo,redo,link,unlink,template",
theme_advanced_buttons2 : "bullist,numlist,image,hr,|,tablecontrols",
theme_advanced_buttons3 : "",
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "left",
theme_advanced_statusbar_location : "bottom",
theme_advanced_resizing : true,
// Skin options
skin : "o2k7",
skin_variant : "silver",
content_style: ".mce-content-body {font-size:15px;font-family:Arial,sans-serif;}",
// Example content CSS (should be your site CSS)
//content_css : "css/editor.css",
// Drop lists for link/image/media/template dialogs
template_external_list_url : "/js/template_list.js",
external_link_list_url : "/js/link_list.js",
external_image_list_url : "/js/image_list.js",
media_external_list_url : "/js/media_list.js",
// Replace values for the template plugin
template_replace_values : {
username : "xxx",
staffid : "xxx"
},
template_templates : [
{
title : "Template",
src : "request_templ/tbl_detail3.html",
description : "Approfondimenti"
},
]
});
在post.php中,将创建新的文本区域:
if(isset($_REQUEST['new_line'])){
$n=$_REQUEST["new_line"];
$text="<tbody class='body_parts' rel=".$n."><tr class='line_add".$n."'>";
$text.="<td><input class='input_parts ui-autocomplete-input' id='part".$n."' placeholder='".$interface["tbl_namep"]." ".$n."'></td>";
$text.="<td><input class='input_parts' id='reference".$n."' placeholder='".$interface["tbl_rif"]." ".$n."'></td>";
$text.="<td><input class='input_parts' id='price".$n."' placeholder='".$interface["tbl_prixt"]." ".$n."'></td>";
$text.="<td><input class='input_parts' id='operation".$n."' placeholder='".$interface["tbl_codopet"]." ".$n."'></td>";
$text.="<td><input class='input_parts' id='description".$n."' placeholder='".$interface["tbl_libt"]." ".$n."'></td>";
$text.="<td><input class='input_parts' id='time".$n."' placeholder='".$interface["tbl_tempt"]."".$n."'></td>";
$text.="<td rowspan='2'><a rel='tps|".$_REQUEST["req"]."' class='new_fft'><img src='images/icons/add_line.png' style='width:20px'>".$interface["lbl_fft_tps"]."</a><br><a rel='pce|".$_REQUEST["req"]."' class='new_fft'><img src='images/icons/add_line.png' style='width:20px'>".$interface["lbl_fft_pce"]."</a></td>";
$text.="</tr>";
$text.="<tr class='line_add".$n."'>";
$text.="<td style='height: 70px'>".$interface["lbl_comment"]."</td>";
$text.="<td style='height: 70px' colspan=5><textarea style='width: 99%' class='input_parts' id='comment".$n."' placeholder='".$interface["tbl_comment"]." ".$n."'></textarea></td>"; //here the new textarea
$text.="<td rowspan='2' style='border:0'><a class='down'><img src='images/down.png'></a><a class='up'><img src='images/up.png'></a><a class='delete_line' rel='".$n."'><img src='images/icons/trash_red.png'></a></td>";
$text.="</tr></tbody>";
echo $text;
}
if(isset($\u请求['new\u行])){
$n=$\u请求[“新行”];
$text=”“;
$text.=“”;
$text.=“”;
$text.=“”;
$text.=“”;
$text.=“”;
$text.=“”;
$text.=''.$interface[“lbl\u fft\u tps”]。“
”$interface[“lbl\u fft\u pce”]。”;
$text.=“”;
$text.=“”;
$text.=''.$interface[“lbl\U注释”];
$text.=“”;//这里是新的文本区域
$text.=“”;
$text.=“”;
echo$文本;
}
那么,怎样才能创造一个新的家庭呢?能帮忙吗?最后,我必须回答自己:
$(document).on("click","#add_line",function(){
var num=parseInt($(this).attr("rel"))+1;
$.post("post.php",{new_line:num,req:$(this).attr("req")},
function(data){
$("#table_answer").parent().append(data);
var comment_id = 'comment' + num;
tinyMCE.execCommand('mceAddControl', true, comment_id); //here
$( "#part"+num ).autocomplete({
source: availableTags2
});
});
$(this).attr("rel",num);
我使用函数execCommand
,将textarea转换为一个tinyMCE
$(document).on("click","#add_line",function(){
var num=parseInt($(this).attr("rel"))+1;
$.post("post.php",{new_line:num,req:$(this).attr("req")},
function(data){
$("#table_answer").parent().append(data);
var comment_id = 'comment' + num;
tinyMCE.execCommand('mceAddControl', true, comment_id); //here
$( "#part"+num ).autocomplete({
source: availableTags2
});
});
$(this).attr("rel",num);