下載下來可是不會用啊,網上也找不到類似的方法,可能都沒遇到過這樣的問題,,經過一個晚上的研究demo及同事一起幫忙,終於研究出了如何使用,自己總結一下,也希望對以後需要的人有所協助.這裡以一個從資料庫讀取和儲存為例子,其它參數請參考kindeditor官方網站
1.首先把下面拷到要用編輯器的路徑
複製代碼 代碼如下:<input type="hidden" name="content1" id="content1" value='<% = databind %>'/>
<input type="hidden" name="content" runat="server" id="content"/>
<script type="text/javascript" src="KindEditor.js"></script>
<script type="text/javascript">
document.getElementById("content").value=document.getElementById("content1").value; //這句是因為不能直接把content做為伺服器控制項才用的,也就是不需要使用<%=this.Content.ClientID%>的,那樣資料讀不出來,
var editor = new KindEditor("editor");
editor.hiddenName = "content"; //這裡是具有Runat="server"屬性的input隱藏框名稱
editor.editorWidth = "100%";
editor.editorHeight = "280px";
editor.show();
function KindSubmit() {
editor.data();
}
</script>
2.儲存按鈕
複製代碼 代碼如下:<asp:Button ID="CreateAdmine" runat="server" Height="22" Text="保 存" Width="42" OnClientClick="KindSubmit()" OnClick="CreateAdmine_Click" /> //要用戶端提交才能儲存
3.後台讀取
Aspx頁: 複製代碼 代碼如下:<input type="hidden" name="content" id = "content" value='<%=EditorValue %>' /> //這裡要用<% =變數 %> 讀取伺服器端EditorValue變數的值為編輯器初始化內容
<input type="hidden" name="contents" runat="server" id="contents"/>
<script type="text/javascript" src="/editor/KindEditor.js"></script>
<script type="text/javascript">
//document.getElementById("<%=this.contents.ClientID %>").value = document.getElementById("content").value;
document.getElementById("contents").value = document.getElementById("content").value;
var editor = new KindEditor("editor");
editor.hiddenName = "contents";
editor.skinPath = "/editor/skins/default/";
editor.iconPath = "/editor/icons/";
editor.imageAttachPath = "/editor/attached/";
editor.imageUploadCgi = "/editor/upload_cgi/upload.aspx";
editor.cssPath = "/editor/common.css";
editor.editorType = "simple";
editor.editorWidth = "500px";
editor.editorHeight = "300px";
editor.show();
function KindSubmit()
{
editor.data();
}
</script>
CS代碼: 複製代碼 代碼如下:protected string EditorValue; //定義一個變數,用戶端讀取這個變數的值賦給編輯器
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
BindData();
}
}
private void BindData()
{
string sql = "select Content from About where id=1";
DataBase db = new DataBase();
SqlDataReader dr = db.ReturnDataReader(sql);
try
{
if (dr.Read())
{
EditorValue = dr["Content"].ToString().Trim(); //在這裡給它賦初始內容
}
}
catch (Exception msg)
{
Response.Write(msg.Message);
}
finally
{
db.Close();
}
}
4.儲存的值
複製代碼 代碼如下:Name = content.Value;