2016-10-24 33 views
4

我在CKEditor中畫一張桌子。如何使用CKEditor將懸停效果添加到<table>?

你可以看到我的表格看起來像這樣。

目前,我想懸停表的列,它會自動檢查亮點圖標,橙色。

我發現改變CSS:

CKEDITOR.config.contentsCss = '/mycustom.css'; 
CKEDITOR.replace('myfield'); 

我不知道如何在表格申請。

我的表有結構,如:

<tr> 
    <td></td> 
    <td></td> 
    <td></td> 
</tr> 
<tr> 
    <td></td> 
    <td></td> 
</tr> 
<tr> 
    <td></td> 
    <td></td> 
</tr> 
+0

還沒有有效的演示上CKEditor的工作,但想到要給它一個去now.Quick問題,您使用的是表插件生成的表? – semuzaboi

+0

僅使用默認工具在工具欄上創建表格。我沒有使用任何插件。 http://ckeditor.com/demo#full – vanloc

回答

1

這裏是一個腳本來突出柱那裏有一個橙色的背景色選中標記。

var CKE = $('.editor'); 
CKE.ckeditor(); 
var columnIndex=0; 

$("#update").click(function(){ 
    // Output CKEditor's result in a result div 
    $("#result").html(CKE.val()); 

    // If there is a table in the result 
    if($("#result").find("table")){ 
     console.log("Table found."); 

     // On mouse over a td 
     $("#result").find("td").on("mouseover",function(){ 
      // find the column index 
      columnIndex = $(this).index(); 

      // Condition is to ensure no highlighting on the 2 firsts columns 
      if(columnIndex>1){ 
       $(this).closest("table").find("tr").each(function(){ 
        var thisTD = $(this).find("td").eq(columnIndex); 

        // If cell is not empty 
        // &nbsp; is the html entity for a space 
        // CKEditor always insert a space in "empty" cells. 
        if(thisTD.html() != "&nbsp;"){ 
         thisTD.addClass("highlight"); 
        } 
       }); 
      } 

      // Clear all hightlights 
     }).on("mouseout",function(){ 
      $(this).closest("table").find("td").removeClass("highlight"); 
     }); 
    } 

    // Console log the resulting HTML (Usefull to post HTML on StackOverflow!!!) 
    console.log("\n"+CKE.val()) 
}); 

我花時間根據您的表格進行演示。
請下次發佈您的HTML!

查看CodePen

+0

我很感激!在我的桌子上建立答案基礎不是你的語言。你太棒了。謝謝 – vanloc

+0

其實...試圖掌握javascript等語言...越南語不是問題(感謝谷歌翻譯!!!)。 Tốtngàychobạn –

+0

謝謝@louyspatricebessette,這真的很有趣。 – vanloc