1. 程式人生 > >Html編輯器,富文字編輯器KindEditor使用

Html編輯器,富文字編輯器KindEditor使用

介紹一個html編輯器,富文字編輯器,KindEditor,比較好用。

官網詳細教程:http://kindeditor.net/about.php

效果圖:


首先,下載kindeditor包。放到專案的JS外掛包中。


在html頁面定義一個textarea,設定長度,寬度。

<textarea id="notice" name="notice" style="width:870px;height:500px;"></textarea>

引入css,js檔案
    <link rel="stylesheet" href="#springUrl('')/plugins/kindeditor/themes/default/default.css" />
    <link rel="stylesheet" href="#springUrl('')/plugins/kindeditor/plugins/code/prettify.css" />

    <script charset="utf-8" src="#springUrl('')/plugins/kindeditor/kindeditor.js"></script>
    <script charset="utf-8" src="#springUrl('')/plugins/kindeditor/lang/zh_CN.js"></script>
    <script charset="utf-8" src="#springUrl('')/plugins/kindeditor/plugins/code/prettify.js"></script>


在JS中初始化html編輯器

var editor;

$(function() {

	KindEditor.ready(function (KE) {
		
		editor = KE.create('#notice');
	});
})

這樣就好噠!


//獲取html編輯器內容

editor.html()

//設定html編輯器內容

editor.html("hello world");