【问题标题】:Replace Tinymce textarea contents on page load在页面加载时替换 Tinymce textarea 内容
【发布时间】:2014-08-05 14:52:01
【问题描述】:

感谢您的留言。实际上,我正在尝试编写一个邮件程序。在那里,我有一个 textarea 字段和一个由 4 个模板组成的下拉菜单。我已经根据下拉选择替换了 textarea 内容。

 $(document).ready(function () {
  $('div#template textarea.mceEditor').html($('div div#template1').text()); 
    $('textarea.mceEditor').attr('readonly','readonly');    
    $('#selecttemplate').change(function () {   

       if($(this).val() == 'template1'){ 
          $('div#template textarea.mceEditor').html($('div div#template1').text());                               $('textarea.mceEditor').attr('readonly','readonly');        

       }
       else if($(this).val() == 'template2'){ 
          $('div#template textarea.mceEditor').html($('div div#template2').text());
          $('textarea.mceEditor').attr('readonly','readonly');

       }
       else if($(this).val() == 'template3'){
          $('div#template textarea.mceEditor').html($('div div#template3').text());
          $('textarea.mceEditor').attr('readonly','readonly');

       }
       else if($(this).val() == 'template4'){
          $('div#template textarea.mceEditor').html($('div div#template4').text());

          $("textarea.mceEditor").removeAttr('readonly');             
       }
    });

我可以在普通的 textarea 中完成此模板更改。当我使用这个 tinymce 集成时,它不会改变 textarea 中的内容。但它会在页面加载时加载第一个下拉内容。

四个不同的(示例)内容根据下拉选择顺序显示在文本区域中:

<div style="display:none;">
 <div id="template1" class="msg">
<?php echo $clickTracker->getAffiliate()->getValue('data1'); ?>
  123
<?php echo $clickTracker->getAffiliate()->getValue('data14'); ?>
</div>
<div id="template2" class="msg">
<?php echo $clickTracker->getAffiliate()->getValue('data1'); ?>
 456
 <?php echo $clickTracker->getAffiliate()->getValue('data10'); ?>
 </div>
 <div id="template3" class="msg">  
 <?php echo $clickTracker->getAffiliate()->getValue('data1'); ?>
 789
 <?php echo $clickTracker->getAffiliate()->getValue('data11'); ?>
 </div>
 <div id="template4" class="msg">
 Type your own message...
 </div>
 </div>

提前致谢。

【问题讨论】:

  • 请说明你想要完成什么。你还是想把那个 textarea 变成一个 TinyMCE-textarea(也许只是在那里显示一些第一个文本)还是你想要用它做一些完全不同的事情?
  • 查看上面的新需求列表...

标签: jquery html tinymce


【解决方案1】:

我猜你可能想像这样使用.setContent():

 if($(this).val() == 'template1'){ 
       tinyMCE.activeEditor.setContent($('div div#template1').text());
 }

文档在这里:http://www.tinymce.com/wiki.php/API3:method.tinymce.Editor.setContent

【讨论】:

  • 感谢您的代码。有用。请告诉我如何禁用/启用编辑。
  • @harry_beginner 谢谢。你可以这样tinyMCE.get('textarea_id').getBody().setAttribute('contenteditable', false);你可能想检查这个问题stackoverflow.com/questions/13881812/…
  • 非常感谢。你节省了很多时间。请再帮忙,我怎么能用邮件发送图像。现在,它不在电子邮件中显示图像了。
  • @harry_beginner,谢谢。您能否详细解释一下您如何尝试通过邮件发送图像?您在服务器端使用 PHP 还是某种脚本语言?
  • 现在,我正在实现一个简单的邮件程序。但我必须发送带有某种模板的 html 电子邮件,其中包含图像和链接。此刻,我已经使用了 php 邮件功能来发送邮件。
猜你喜欢
  • 1970-01-01
  • 2015-05-24
  • 2011-01-07
  • 1970-01-01
  • 1970-01-01
  • 2018-12-23
  • 1970-01-01
  • 1970-01-01
  • 2012-06-26
相关资源
最近更新 更多