我需要将TinyMCE和图像上传按钮对话框与自己的Web应用程序集成在一起-但是我需要将图像上传与一些自定义变量一起发布到我的PHP代码中。
我的PHP使用以下激活代码调用tinyMCE.init:

原始PHP代码(触发编辑器)...

<?php

$js='
tinyMCE.init({
    mode : "textareas",
    theme : "advanced",
    plugins : "spellchecker,advhr,table,addimg",
    theme_advanced_buttons1 :     "cut,copy,paste,|,bold,italic,underline,|,justifyleft,justifycenter,justifyright,formatselect,zoom, blockquote,|,bullist,numlist,|,outdent,indent,|,undo,redo,|,link,unlink,anchor,addimg,|,code,preview,|,forecolor,backcolor",
    theme_advanced_buttons2 : "tablecontrols,|,spellchecker,advhr,removeformat,|,sub,sup,|,charmap,visualaid",
    theme_advanced_buttons3 : "",
    theme_advanced_toolbar_location : "top",
    theme_advanced_toolbar_align : "left",
    theme_advanced_statusbar_location : "bottom",
    theme_advanced_resizing : true,
    content_css : "'.config::siteurl.'/css/myStyle.css"
});


....这将通过自定义按钮“ addimg”激活编辑器;当我单击addimg自定义按钮时,它将按预期触发自定义dialog.htm;但是我需要的是此dialog.htm包含我的变量,以便在发布表单时,接收方的PHP可以利用它们

dialog.htm表格...

.
.
.
<form id='file_upload_form' name='file_upload_form' enctype='multipart/form-data'     action='myUploader.php' method='POST'>
    <input type='text' name='MySpecialId’ value='xxxx'>
     <table width=100%>
     <tr valign=top>
     <td width=100>Please choose a file: </td>
     <td align=left>
         <input style='width: 100%;'  id='myFile' name='myFile' type='file'>
     </td>
     </tr>
 </table>
</form>
.
.


问题是如何从原始PHP调用程序中获取一个值到dialog.htm中,以便在上述表单中设置MySpecialId值?我以为我可以使用dialog.js AddImgDialog.init()js方法中的Java脚本来设置表单,但是又如何才能使TinyMCE工具栏将值从调用PHP传递给自定义按钮dialog.js?

例如

var AddImgDialog = {
    init : function() {
    alert( 'My passed through value is xxxxx' );
},
.
.


有什么提示吗?
谢谢
道明

最佳答案

您可以在tinyMCE.init()中设置变量,例如:

tinyMCE.init({
    mode : "textareas",
    /*more settings*/
    myVariable:12345
});


可以通过tinyMCE.settings.myVariable在dialog.htm中访问此变量。
为了使输入更容易到达,请给它一个ID,例如myInputID。
现在您可以设置该值(将以下指令放置在输入之后的某处)

document.getElementById('myInputID').value=tinyMCE.settings.myVariable;

关于javascript - 如何集成TinyMCE按钮并传递变量,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7936224/

10-12 07:11