counter
counter

kindeditor 应用动态生成的控件

1.首先在js中实现,页面里使用了UpdatePanel

js引用:

 
View Code
1  <script src="../js/jquery/jquery.js" type="text/javascript"></script>
2     <link rel="stylesheet" href="../js/kindeditor/themes/default/default.css" />
3     <link rel="stylesheet" href="../js/kindeditor/plugins/code/prettify.css" />
4     <script type="text/javascript" charset="utf-8" src="../js/kindeditor/kindeditor-min.js"></script>
5     <script type="text/javascript" charset="utf-8" src="../js/kindeditor/lang/zh_CN.js"></script>
6     <script type="text/javascript" charset="utf-8" src="../js/kindeditor/plugins/code/prettify.js"></script>

具体实现:因为控件是动态生成的,查看前台代码可知,一旦加上kindeditor效果,自己原有的控件会被隐藏,其中最重要的是保存动态库控件的值,所以必须同步动态控件与kindeditor对应的值。

View Code
 1  <script type="text/javascript">
 2         function jz() {
 3             $("textarea").each(function () {
 4                 KindEditor.create('#' + $(this).attr("id"), { uploadJson: '/Handlers/UploadNoticeImage.ashx?type=intro', items: [
 5                                             'source', '|', 'undo', 'redo', '|', 'preview', 'template', 'cut', 'copy', 'paste',
 6                                             'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
 7                                             'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'clearhtml', 'selectall', '|',
 8                                             'removeformat', '|', 'image', 'flash', 'link', 'unlink', '|', 'fullscreen'], allowFlashUpload: false, width: '700px'
 9                                             , afterBlur: function () {
10                                                 this.sync();
11 
12                                                 K.ctrl(document, 13, function () {
13                                                     this.sync();
14                                                     K('form[name=example]')[0].submit();
15                                                 });
16                                                 K.ctrl(this.edit.doc, 13, function () {
17                                                     this.sync();
18                                                     K('form[name=example]')[0].submit();
19                                                 });
20                                             }
21                 });
22                 prettyPrint();
23             });
24         };
25     </script>

2.当页面加载完毕的时候 进行重新加载

View Code
1     Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(jz);

 

3.后台加载:初始化页面的时候,手动在后台加载。

View Code
1 ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "js", "jz()", true);

 

 

4.若前台控件是固定的话:

View Code
 1  $("textarea").each(function () {
 2                 i++;
 3                 arr[i] = $(this).attr("id");
 4                 if (i > 2) {
 5                     KindEditor.create('#' + arr[i], { uploadJson: '/Handlers/UploadNoticeImage.ashx?type=intro', items: [
 6                                             'source', '|', 'undo', 'redo', '|', 'preview', 'template', 'cut', 'copy', 'paste',
 7                                             'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
 8                                             'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'clearhtml', 'selectall', '|',
 9                                             'removeformat', '|', 'image', 'flash', 'link', 'unlink', '|', 'fullscreen'], allowFlashUpload: false
10                     });
11                 };
12             });
posted @ 2012-11-06 11:16  bfy  阅读(765)  评论(0编辑  收藏  举报