CKeditor富文字編輯器的使用
首先:先下載CKeditor
引用:<script type="text/javascript" src="/Scripts/ckeditor/ckeditor.js"></script>
//前臺程式碼
<table>
<tr>
<td style="width: 100px; text-align: right;">內容:</td>
<td colspan="3" width="800" height="200">
<textarea id="txt_MsgContent" name="MsgContent" style="width: 270px; height: 100px; " maxlength="2000"></textarea>
<label id="lbl_MsgContent"></label>
</td>
<td><input id="txt_Content" type="text" style="display:none" /></td>
</tr>
</table>
<script type="text/javascript">
//將textarea替換成編輯器
var MyCKenitor = CKEDITOR.replace('txt_MsgContent', {language : 'zh-cn',uiColor: '#eeeeee', toolbar: [
{ name: 'basicstyles', groups: ['basicstyles', 'cleanup'], items: ['Bold', 'Italic', 'Underline', 'Strike', 'RemoveFormat'] },
{ name: 'paragraph', groups: ['list', 'indent', 'blocks', 'align', 'bidi'], items: ['NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', '-', 'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock'] },
{ name: 'insert', items: ['Image','HorizontalRule', 'SpecialChar'] },
{ name: 'colors', group: ['colorbutton', 'colordialog'], items: ['TextColor', 'BGColor'] },
{ name: 'forms' },
'/',
{ name: 'styles', items: ['Styles', 'Format', 'Font', 'FontSize'] },
{ name: 'others' }
]
});//自定義配置編輯器, 'Link', 'Unlink'
//是否在選擇顏色時顯示“其它顏色”選項
CKEDITOR.config.colorButton_enableMore = false;
CKEDITOR.config.image_previewText = ' '; //預覽區域顯示內容
CKEDITOR.config.filebrowserImageUploadUrl = "後臺方法地址/upload";//設定檔案上傳檔案/圖片地址,
</script>
//後臺程式碼
#region 上傳檔案/圖片Upload()
/// <summary>
/// 上傳檔案/圖片
/// </summary>
/// <param name="upload"></param>
/// <returns></returns>
public ActionResult Upload(HttpPostedFileBase upload)
{
var fileName = System.IO.Path.GetFileName(upload.FileName);
//if (upload.ContentLength > 1024 * 1024 * 1)
//{
// return null;
// return Content("<script>alert('圖片大小不符合,大小不超過1M!');</script>"); //<script></script>alert('圖片大小不符合,大小不超過1M!')
//}
//var filePhysicalPath = Server.MapPath("/ImgFile/" + fileName);//我把它儲存在網站根目錄的 ImgFile 資料夾
string filePath = ConfigurationManager.AppSettings["ImgFile"];
var filePhysicalPath = Server.MapPath(filePath + fileName);
upload.SaveAs(filePhysicalPath);
//var url = ConfigurationManager.AppSettings["MessageFilePath"] + "/PMSFile/" + fileName;
var url = ConfigurationManager.AppSettings["ImgFile"] + fileName;
var CKEditorFuncNum = System.Web.HttpContext.Current.Request["CKEditorFuncNum"];
//上傳成功後,我們還需要通過以下的一個指令碼把圖片返回到第一個tab選項
return Content("<script>window.parent.CKEDITOR.tools.callFunction(" + CKEditorFuncNum + ", \"" + url + "\");</script>");
}
#endregion
//遇到的一些問題
1.儲存訊息時:(前臺傳到後臺會轉義 )
前臺傳後臺: var MsgContent = CKEDITOR.tools.htmlEncode(MyCKenitor.getData());//對CKeditor編輯器取出的資料進行二次解析
後臺存資料庫:Server.HtmlDecode(MsgContent);
2.前臺獲取後臺資料顯示在頁面時:
後臺傳前臺:document.getElementById('txt_MsgContent').innerHTML = CKEDITOR.tools.htmlDecode(後臺傳的資料);
相關推薦
【解決】獲取到ckeditor富文字編輯器body節點下的內容
html頁面: <textarea name="description" id="description" /></textarea> <!-- 富文字編輯器 --> <script th:src="@{/plugins/ckeditor/
CKEditor富文字編輯器的使用及bug修改
CKEditor富文字編輯器的使用及bug修改 為什麼要用富文字編譯器? 在運營後臺,運營人員需要錄入並編輯詳情資訊, 詳情資訊不是普通的文字,可以是包含了HTML語法格式的字串。為了快速簡單的讓使用者能夠在頁面中編輯帶格式的文字,我們引入富文字編輯器。富文字
CKEditor富文字編輯器-django-admin使用
CKEditor富文字編輯器 在運營後臺,運營人員需要錄入商品並編輯商品的詳情資訊,而商品的詳情資訊不是普通的文字,可以是包含了HTML語法格式的字串。為了快速簡單的讓使用者能夠在頁面中編輯帶格式的文字,我們引入富文字編輯器。富文字即具備豐富樣式格式的文字。 我們使用功能
Django專案之CKEditor富文字編輯器
1. 安裝 pip install django-ckeditor 2. 新增應用 在INSTALLED_APPS中新增 INSTALLED_APPS = [ ... 'ckedito
ckeditor富文字編輯器上傳圖片的具體步驟
ckeditor相關配置和應用可以參考:https://blog.csdn.net/sayoko06/article/details/81450441 第一步:引入ckeditor的js <td> <textarea name="descripti
使用ckeditor富文字編輯器頁面解析文字樣式方法
從資料庫讀寫的是這樣的<p><strong>hello,world<strong></p> 但是這樣顯示在網頁上不是我們想要的,我們想要的是 hello,world struts2的解決辦法是<s:property
springmvc後臺如何接收ckeditor富文字編輯器編輯的內容
1把ckeditor的文字區,改成文章類的body,後臺用mvc的屬性自動封裝來接收,接收一個article類就行了 2吧文字區當string來接收 資料庫中如何儲存呢? 使用hibernate自動生成表的時候,body型別是vchar,但是不合理,一般就用text,不用blob的原因是中文亂碼還要單獨
CKeditor富文字編輯器的使用
首先:先下載CKeditor 引用:<script type="text/javascript" src="/Scripts/ckeditor/ckeditor.js"></script> //前臺程式碼 <table> <tr&
ckeditor富文字編輯器上傳圖片+html編輯+strtus
效果圖:1需要的檔案(ckeditor.js;config.js):點選開啟連結2.jsp<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
在Django的admin中使用富文字編輯器 CKEditor
開發環境 : Python 3.5 Django 1.11 CKEditor安裝: pip install django-ckeditor Django的settings.py中的註冊和配置 在INSTALL_APP進行註冊: ‘cked
富文字編輯器學習(Ckeditor的使用)
幾種富文字編輯器的介紹UEditor/kindeditor/simditor/bootstrap-wysiwyg/wangEditor/CKEditor/tinymcehttps://www.cnblogs.com/linkstar/p/6858995.htmlhttps:/
前端富文字編輯器ckeditor的使用
一、匯入js檔案 <script src="js/plugins/ckeditor/ckeditor.js"></script> 將下載的檔案匯入相應html目錄下 二、html程式碼 <textarea rows="20" class="
富文字編輯器CKEditor的使用
CKEditor是一款由javascript編寫的富文字網頁編輯器,它可以填寫文字、插入圖片、視訊、Excel等富媒體資訊. 介紹下它的使用: 一:從官網下載ckeditor。解壓。 二:將ckeditor整個資料夾放到專案資源目錄下。 三:在要新增ckeditor的頁面中
富文字編輯器 CKeditor 配置使用 (帶附件)
Ckeditor下載地址: http://ckeditor.com/download 1.CKeditor的基本配置 var textval=CKEDITOR.instances.TextArea1.getData(
富文字編輯器CKEditor的使用及同步問題
關於富文字編輯器,我個人使用的是CKEditor,感覺使用起來挺方便,下面就來看看CKEditor的使用。 然後我們把需要的檔案拖入我們的程式中,在頭部將你的ckeditor.js匯入 <script src="ckeditor/ckeditor.js" type=
在 Django Model 中新增富文字編輯器 CKEditor
1. 安裝 django-ckeditor pip install django-ckeditor 2. 新增 ckeditor 到 settings.py 中的 INSTALLED_APPS 裡 3. 新增 CKEDITOR_UPLOAD_PATH 的配置到 se
富文字編輯器CKEditor配置及使用
注:使用CKEditor版本為js版本的CKEditor 4.8.0,所有配置均參考自CKEditor官方API:https://docs.ckeditor.com/,以及實踐經驗 一、快速使用 CKEditor官網下載js外掛 進入官網https:
django部落格開發:新增富文字編輯器ckeditor
Markdown用的不太習慣,於是決定新增一個富文字編輯器。ckeditor是一個老牌的編輯器,GitHub上有一個第三方模組django-ckeditor封裝了所有功能,把import到我們的專案裡,然後設定一下引數,就可輕鬆使用了。EDIT:通過網友反應的一些問題,以及後
富文字編輯器CKEditor
本文包括安裝配置、使用 CKEditor以及使用CKFinder實現圖片上傳功能 說在前面,CKEditor和CKFinder有很詳細很詳細的文件說明,一切都能在裡面找到 1. 下載 CKEditor包括Basic、St
Flask學習10:Flask專案整合富文字編輯器CKEditor 上傳圖片
CKEditor下載地址:https://ckeditor.com/ckeditor-4/download/ 訪問CKeditor官方網站,進入下載頁面,選擇Standard Package(一般情況