原文鏈接:http://blog.csdn.net/lovelyelfpop/article/details/51678742
參考:https://www.cnblogs.com/xiangsj/p/6244794.html
打開ueditor.all.js
1、找到下面的代碼,修改
1 utils.each(tables, function (table) { 2 removeStyleSize(table, true); 3 domUtils.removeAttributes(table, ['style']); //改這里,原來是 ['style', 'border'] 4 utils.each(domUtils.getElementsByTagName(table, "td"), function (td) { 5 if (isEmptyBlock(td)) { 6 domUtils.fillNode(me.document, td); 7 } 8 removeStyleSize(td, true); 9 }); 10 }); //這是為了不讓UEditor去掉粘貼的表格的邊框,也就是table元素的border屬性(不是border內聯樣式)
2、UEditor插入的表格實際是沒有邊框的,編輯器中看到邊框,其實是因為編輯器里面(<iframe>中)有下面這個全局css
td,th{ border:1px solid #DDD; }
3、最后就是table上右鍵菜單中有個"表格-設置表格邊線可見"的功能。這個功能會讓表格顯示出實線邊框,實際前台展示也是有邊框的。
現在td是有實線邊框的,可是th卻還是虛線,所以要改下面的代碼,增加一段對th的處理
注意:th就是表格標題列/行。可以用右鍵菜單"表格-插入表格標題列/行"插入th
execCommand: function () { var table = getTableItemsByRange(this).table; utils.each(domUtils.getElementsByTagName(table,'td'),function(td){ td.style.borderWidth = '1px'; td.style.borderStyle = 'solid'; td.style.borderColor = 'windowtext'; }); //增加下面一段 utils.each(domUtils.getElementsByTagName(table,'th'),function(th){ th.style.borderWidth = domUtils.getComputedStyle(th, "border-width"); th.style.borderStyle = 'solid'; th.style.borderColor = 'windowtext'; }); }
最后如果你用的是ueditor.all.min.js,需要將改過的代碼壓縮一份min版本。
