TinyMCE只展示了第一轮

时间:2014-06-28 11:02:48

标签: php tinymce

TinyMCE有轻微问题。

我有一个foreach循环和第一个运行它的标签,标签显示为tinymce。然而,这个foreach和tinymce的第二个循环是不可见的。唯一显示的是html textarea。

我认为这与textareas的id以及如何实现他们的textareas有关。所以我认为下次循环发生时,Id必须与之前的不同。

我是否正确地思考这个?如果是这样,我该怎么做呢?

以下是我正在使用的代码。

<table width="90%">
 <thead>
   <th align="left">Title</th>
   <th align="left">Sub Title</th>
   <th align="left">Story</th>
 </thead>
 <?php
   $rowSet = $db->selectAllNoLimitFootball("news");

   foreach($rowSet as $key => $news){
   $id = $news['id']; //Assign the id of the array instance to a variable to use on the button below
   echo "<tr>"; 
   echo "<td><textarea id=\"title2\" name=\"title\">".$news['title']."</textarea></td>";
   echo "<td><textarea id=\"subtitle2\" name=\"subtitle\">".$news['subtitle']."</textarea></td>";
   echo "<td><textarea id=\"story2\" name=\"story\">".$news['story']."</textarea></td>";
   echo "<tr><td><br>Live: <input type=\"checkbox\" name=\"live\" id=\"live\" value=\"1\"><br><br></td></tr>";
   echo "</tr>"; 
   echo "<tr><td colspan=\"3\"><br><button class=\"submit\" name=\"remove-news-id\" value=\"$id\">Delete</button>
   <button class=\"submit\" name=\"update-news-id\" value=\"$id\">Update</button></td></tr>";
   echo "<tr><td colspan=\"3\"><hr></td></tr>";
   }
?>
</table>

以下是javascript。

    tinymce.init({
        selector: "textarea",
        plugins: [
            "advlist autolink autosave link image lists charmap print preview hr anchor pagebreak spellchecker",
            "searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime media nonbreaking",
            "table contextmenu directionality emoticons template textcolor paste fullpage textcolor"
        ],

        toolbar1: "newdocument fullpage | bold italic underline strikethrough | alignleft aligncenter alignright alignjustify | styleselect formatselect fontselect fontsizeselect",
        toolbar2: "cut copy paste | searchreplace | bullist numlist | outdent indent blockquote | undo redo | link unlink anchor image media code | inserttime preview | forecolor backcolor",
        toolbar3: "table | hr removeformat | subscript superscript | charmap emoticons | print fullscreen | ltr rtl | spellchecker | visualchars visualblocks nonbreaking template pagebreak restoredraft",

        menubar: false,
        toolbar_items_size: 'small',

        style_formats: [
            {title: 'Bold text', inline: 'b'},
            {title: 'Red text', inline: 'span', styles: {color: '#ff0000'}},
            {title: 'Red header', block: 'h1', styles: {color: '#ff0000'}},
            {title: 'Example 1', inline: 'span', classes: 'example1'},
            {title: 'Example 2', inline: 'span', classes: 'example2'},
            {title: 'Table styles'},
            {title: 'Table row 1', selector: 'tr', classes: 'tablerow1'}
        ]

    });

1 个答案:

答案 0 :(得分:0)

是的,它是一个ID问题。我在Django应用程序中遇到了同样的问题:Django-TinyMCE with Multiple Forms

增加ID(#id_1,#id_2等)将为您解决。这是一个Django模板实现:Apply tinyMCE settings to dynamicly created textarea