2013-01-03 118 views
1

我想顯示一個Ck編輯器在動態加載加載頁面,我用下面的腳本,但唯一的一個ck編輯器出現別人看起來像文本區域?CK編輯動態頁

 <script > 
      function refer(format, id) 
      { 

      if (window.XMLHttpRequest) 
      {// code for IE7+, Firefox, Chrome, Opera, Safari 
       req=new XMLHttpRequest(); 

      } 
      else 
      {// code for IE6, IE5 
       req=new ActiveXObject("Microsoft.XMLHTTP"); 

      } 
      var strURL="referformat.php?format="+format+"&id="+id; 

      if (req) 
      { 
       req.onreadystatechange = function() { 



        if (req.readyState == 4) { 
         // only if "OK" 

         if (req.status == 200) 
         { 

          //var a=document.getElementById('editor1').value=""; 
          // alert(a); 

          // alert('i am here'); 
          // CKEDITOR.instances.editor1.setData(req.responseText); 
           document.getElementById('refformat').innerHTML=req.responseText; 





       CKEDITOR.replace('editor1', 
        { 

         fontSize_sizes : "8px;9px;10px;12px;14px;16px;18px;20px;22px;24px;26px;28px;30px;32px;34px", 
         toolbar : 
         [ 
          ['Bold', 'Italic','Underline'], 
          ['Source', '-', 'Undo','Redo'], 
          ['Format','Font','FontSize'], 
          ['TextColor','BGColor'], 
          ['NumberedList','BulletedList','-','Blockquote'], 
          ['Link', 'Unlink','SpecialChar'], 
         ], 
         // Strip CKEditor smileys to those commonly used in BBCode. 
         smiley_images : 
         [ 
          'regular_smile.gif','sad_smile.gif','wink_smile.gif','teeth_smile.gif','tounge_smile.gif', 
          'embaressed_smile.gif','omg_smile.gif','whatchutalkingabout_smile.gif','angel_smile.gif','shades_smile.gif', 
          'cry_smile.gif','kiss.gif' 
         ], 
         smiley_descriptions : 
         [ 
          'smiley', 'sad', 'wink', 'laugh', 'cheeky', 'blush', 'surprise', 
          'indecision', 'angel', 'cool', 'crying', 'kiss' 
         ] 
       }); 

       CKEDITOR.replace('editor2', 
        { 

         fontSize_sizes : "8px;9px;10px;12px;14px;16px;18px;20px;22px;24px;26px;28px;30px;32px;34px", 
         toolbar : 
         [ 
          ['Bold', 'Italic','Underline'], 
          ['Source', '-', 'Undo','Redo'], 
          ['Format','Font','FontSize'], 
          ['TextColor','BGColor'], 
          ['NumberedList','BulletedList','-','Blockquote'], 
          ['Link', 'Unlink','SpecialChar'], 
         ], 
         // Strip CKEditor smileys to those commonly used in BBCode. 
         smiley_images : 
         [ 
          'regular_smile.gif','sad_smile.gif','wink_smile.gif','teeth_smile.gif','tounge_smile.gif', 
          'embaressed_smile.gif','omg_smile.gif','whatchutalkingabout_smile.gif','angel_smile.gif','shades_smile.gif', 
          'cry_smile.gif','kiss.gif' 
         ], 
         smiley_descriptions : 
         [ 
          'smiley', 'sad', 'wink', 'laugh', 'cheeky', 'blush', 'surprise', 
          'indecision', 'angel', 'cool', 'crying', 'kiss' 
         ] 
       }); 

        CKEDITOR.replace('editor4', 
        { 

         fontSize_sizes : "8px;9px;10px;12px;14px;16px;18px;20px;22px;24px;26px;28px;30px;32px;34px", 
         toolbar : 
         [ 
          ['Bold', 'Italic','Underline'], 
          ['Source', '-', 'Undo','Redo'], 
          ['Format','Font','FontSize'], 
          ['TextColor','BGColor'], 
          ['NumberedList','BulletedList','-','Blockquote'], 
          ['Link', 'Unlink','SpecialChar'], 
         ], 
         // Strip CKEditor smileys to those commonly used in BBCode. 
         smiley_images : 
         [ 
          'regular_smile.gif','sad_smile.gif','wink_smile.gif','teeth_smile.gif','tounge_smile.gif', 
          'embaressed_smile.gif','omg_smile.gif','whatchutalkingabout_smile.gif','angel_smile.gif','shades_smile.gif', 
          'cry_smile.gif','kiss.gif' 
         ], 
         smiley_descriptions : 
         [ 
          'smiley', 'sad', 'wink', 'laugh', 'cheeky', 'blush', 'surprise', 
          'indecision', 'angel', 'cool', 'crying', 'kiss' 
         ] 
       }); 


       CKEDITOR.replace('editor3', 
        { 

         fontSize_sizes : "8px;9px;10px;12px;14px;16px;18px;20px;22px;24px;26px;28px;30px;32px;34px", 
         toolbar : 
         [ 
          ['Bold', 'Italic','Underline'], 
          ['Source', '-', 'Undo','Redo'], 
          ['Format','Font','FontSize'], 
          ['TextColor','BGColor'], 
          ['NumberedList','BulletedList','-','Blockquote'], 
          ['Link', 'Unlink','SpecialChar'], 
         ], 
         // Strip CKEditor smileys to those commonly used in BBCode. 
         smiley_images : 
         [ 
          'regular_smile.gif','sad_smile.gif','wink_smile.gif','teeth_smile.gif','tounge_smile.gif', 
          'embaressed_smile.gif','omg_smile.gif','whatchutalkingabout_smile.gif','angel_smile.gif','shades_smile.gif', 
          'cry_smile.gif','kiss.gif' 
         ], 
         smiley_descriptions : 
         [ 
          'smiley', 'sad', 'wink', 'laugh', 'cheeky', 'blush', 'surprise', 
          'indecision', 'angel', 'cool', 'crying', 'kiss' 
         ] 
       }); 

       //]]> 





         } else { 
          alert("There was a problem while using XMLHTTP:\n" + req.statusText); 
         } 
        } 
       }  
       req.open("GET", strURL, true); 
       req.send(null); 
      } 
     } 

</script> 

期運用這一點,我想顯示3的CKEditor,但CKEditor的僅適用於第一個文本區域,剩餘的2文本區域的CKEditor不工作,我該如何解決這個問題

外部網頁HTML是

f(strtolower(str_replace(' ','',$reffername))=='injuryqedltd' && $format=='ia_format') 
         { 
          ?> 
          <table> 
          <tr> 
          <td> 

           <strong>Findings on Initial Examination</strong> 
          </td> 
          <td> 
          <textarea cols="80" rows="10" name="editor2" id="editor2" class="required textarea" title="Enter the Message"><?php echo $result[0]['Initialexam'];?></textarea> 


          </td> 
         </tr> 

         <tr> 
          <td> 

           <strong>Details of Treatment to be Provided</strong> 
          </td> 
          <td> 
          <textarea cols="80" rows="10" name="editor3" id="editor3" class="required textarea" title="Enter the Message"><?php echo $result[0]['Detailtreatment'];?></textarea> 


          </td> 
         </tr> 
         <tr> 
          <td> 

           <strong>Benefit of Treatment to be Provided</strong> 
          </td> 
          <td> 
          <textarea cols="80" rows="10" name="editor4" id="editor4" class="required textarea" title="Enter the Message"><?php echo $result[0]['BeTreatment'];?></textarea> 


          </td> 
         </tr> 
         </table> 

       <?php  } 
       else if(strtolower(str_replace(' ','',$reffername))=='injuryqedltd' && $format=='fa_format') { 


        ?> 
          <table> 
          <tr> 
          <td> 

           <strong>Details of Treatment Provided</strong> 
          </td> 
          <td> 
          <textarea cols="80" rows="10" name="editor5" id="editor5" class="required textarea" title="Enter the Message"><?php echo $result[0]['Initialexam'];?></textarea> 


          </td> 
         </tr> 

         <tr> 
          <td> 

           <strong>Benefit of Treatment Provided</strong> 
          </td> 
          <td> 
          <textarea cols="80" rows="10" name="editor6" id="editor6" class="required textarea" title="Enter the Message"><?php echo $result[0]['Detailtreatment'];?></textarea> 


          </td> 
         </tr> 
         <tr> 
          <td> 

           <strong>Discharge Summary</strong> 
          </td> 
          <td> 
          <textarea cols="80" rows="10" name="editor7" id="editor7" class="required textarea" title="Enter the Message"><?php echo $result[0]['BeTreatment'];?></textarea> 


          </td> 
         </tr> 
         </table> 

       <?php 



       } 
       else 
        { 
         $sel="SELECT $format as rff FROM `tbl_referreg` WHERE `ref_id`='".$id."'"; 
     $reffer=$objAdmin->ExecuteQuery($sel,'select'); 

?> 
      <table><tr> 
      <td><strong>Assessment Format:</strong></td> 
      <td><textarea cols="80" style="margin-left:32px;" rows="30" name="editor1" id="editor1" class=" textarea" title="Enter the Message"><?php echo $reffer[0]['rff']; ?></textarea></td></tr></table> 

       <?php } 
       ?> 
+2

你能不能顯示你的HTML也能生成textareas? – Nenotlep

+0

嗨,我編輯了一個 – MANIKANDAN

回答

0

我試圖複製在看HTML和JS上,看到您要更換editor1,editor2,editor3和editor4但你也有編輯文本域5-7。那些你錯過了嗎?如果是這樣,只需在需要的地方添加.replace(...)即可。

我會首先建議您清理一下代碼,以便您和其他人更容易看清發生了什麼。這裏是我用來測試的例子:

<textarea cols="80" rows="10" name="editor2" id="editor2" class="required textarea" title="Enter the Message">A</textarea> 
<textarea cols="80" rows="10" name="editor3" id="editor3" class="required textarea" title="Enter the Message">B</textarea> 
<textarea cols="80" rows="10" name="editor4" id="editor4" class="required textarea" title="Enter the Message">C</textarea> 
<textarea cols="80" rows="10" name="editor5" id="editor5" class="required textarea" title="Enter the Message">D</textarea> 
<textarea cols="80" rows="10" name="editor6" id="editor6" class="required textarea" title="Enter the Message">E</textarea> 
<textarea cols="80" rows="10" name="editor7" id="editor7" class="required textarea" title="Enter the Message">F</textarea> 
<textarea cols="80" style="margin-left:32px;" rows="30" name="editor1" id="editor1" class=" textarea" title="Enter the Message">G</textarea> 

<script type="text/javascript" src="http://cdn.jsdelivr.net/ckeditor/4.0/ckeditor.js"></script> 
<script> 
    function refer() 
    { 
     var config = {     
      fontSize_sizes : "8px;9px;10px;12px;14px;16px;18px;20px;22px;24px;26px;28px;30px;32px;34px", 
      toolbar : 
      [ 
      ['Bold', 'Italic','Underline'], 
      ['Source', '-', 'Undo','Redo'], 
      ['Format','Font','FontSize'], 
      ['TextColor','BGColor'], 
      ['NumberedList','BulletedList','-','Blockquote'], 
      ['Link', 'Unlink','SpecialChar'], 
      ], 
      // Strip CKEditor smileys to those commonly used in BBCode. 
      smiley_images : 
      [ 
      'regular_smile.gif','sad_smile.gif','wink_smile.gif','teeth_smile.gif','tounge_smile.gif', 
      'embaressed_smile.gif','omg_smile.gif','whatchutalkingabout_smile.gif','angel_smile.gif','shades_smile.gif', 
      'cry_smile.gif','kiss.gif' 
      ], 
      smiley_descriptions : 
      [ 
      'smiley', 'sad', 'wink', 'laugh', 'cheeky', 'blush', 'surprise', 
      'indecision', 'angel', 'cool', 'crying', 'kiss' 
      ] 
     }; 

     CKEDITOR.replace('editor1', config); 
     CKEDITOR.replace('editor2', config); 
     CKEDITOR.replace('editor4', config); 
     CKEDITOR.replace('editor3', config); 
     // Those got replaced nicely 
    } 
</script> 
+0

縮進是有點關閉,你必須手工調用(),但我希望它足夠清晰,看看我的意思 – Nenotlep

+0

我試過這個,但只有一個CKeditor會出現? – MANIKANDAN

+0

對我來說,所有4個都出現了,真奇怪!您可以鏈接到您的網站或將它上傳到我可以看到的地方嗎?只是爲了更容易測試:) – Nenotlep