基於ThinkPHP的線上編輯器調用

來源:互聯網
上載者:User

標籤:style   blog   http   java   color   使用   os   檔案   

開源的線上編輯器有很多,比如FCKEditor,UEditor,Kindeditor等,調用方式也都大同小異

下面列舉UEditor線上編輯器外掛程式在ThinkPHP裡面的應用

1、Ueditor:http://ueditor.baidu.com/website/download.html(注意編碼)

2、使用ThinkPHP版本為ThinkPHP3.1.2

 

先下載Ueditor外掛程式解壓放置ThinkPHP項目的根目錄並將檔案夾名稱重新命名為ueditor

如:

編寫測試類別:

1 class IndexAction extends Action {2     public function index(){3         $this->display();4     }

對應映射Html靜態頁面:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"><head>    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">    <title>Ueditor</title>    <script type="text/javascript" src="__ROOT__/ueditor/ueditor.config.js"></script>     <script type="text/javascript" src="__ROOT__/ueditor/ueditor.all.js"></script>          <script type="text/javascript">            function edit(){                UE.getEditor(‘content‘);                }        </script></head><body onload="edit()">    <form action="__URL__/edit" method="post">        標題:<br/>        <input type="text" name="info"/><br/>        內容:<textarea id="content" name="content" style="width:700px;height:300px;"></textarea>        <input type="submit" value="提交"/>    </form></body></html>

在靜態頁面HTML用Javascript調用,分別引入ueditor.config.js、ueditor.all.js兩個JS檔案,可直接用UE.getEditor(參數1,{參數2});進行調用

參數1:

需要和下面的TextArea的ID名對應。

參數2:(非必須) 

一些初始化參數,比如寬度,高度,各種按鈕,樣式等。

若不填寫此參數,預設下是用TextArea的Style樣式的寬高來定義Ueditor

效果如:

提交表單:

 

-------------------------------------------------------------華麗的分割線-------------------------------------------------------------------

來說下關於參數二,畢竟一般的線上編輯器是不需要那麼多功能的,使其簡潔。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"><head>    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">    <title>Ueditor</title>    <script type="text/javascript" src="__ROOT__/ueditor/ueditor.config.js"></script>     <script type="text/javascript" src="__ROOT__/ueditor/ueditor.all.js"></script>          <script type="text/javascript">            function edit(){                UE.getEditor(‘content‘,{                  //這裡可以選擇自己需要的工具按鈕名稱,此處僅選擇如下五個                  toolbars:[[‘FullScreen‘, ‘Source‘, ‘Undo‘, ‘Redo‘,‘bold‘,‘test‘]],                  //focus時自動清空初始化時的內容                  autoClearinitialContent:true,                  //關閉字數統計                  wordCount:false,                  //關閉elementPath                  elementPathEnabled:false,                  //預設的編輯地區高度                  initialFrameHeight:300                  //更多其他參數,請參考ueditor.config.js中的配置項              });              }        </script></head><body onload="edit()">    <form action="__URL__/edit" method="post">        標題:<br/>        <input type="text" name="info"/><br/>        內容:<textarea id="content" name="content" style="width:700px;height:300px;"></textarea>        <input type="submit" value="提交"/>    </form></body></html>

關於參數二的toolbars在開發文檔ueditor.config.js中有給出:

toolbars: [[            ‘fullscreen‘, ‘source‘, ‘|‘, ‘undo‘, ‘redo‘, ‘|‘,            ‘bold‘, ‘italic‘, ‘underline‘, ‘fontborder‘, ‘strikethrough‘, ‘superscript‘, ‘subscript‘, ‘removeformat‘, ‘formatmatch‘, ‘autotypeset‘, ‘blockquote‘, ‘pasteplain‘, ‘|‘, ‘forecolor‘, ‘backcolor‘, ‘insertorderedlist‘, ‘insertunorderedlist‘, ‘selectall‘, ‘cleardoc‘, ‘|‘,            ‘rowspacingtop‘, ‘rowspacingbottom‘, ‘lineheight‘, ‘|‘,            ‘customstyle‘, ‘paragraph‘, ‘fontfamily‘, ‘fontsize‘, ‘|‘,            ‘directionalityltr‘, ‘directionalityrtl‘, ‘indent‘, ‘|‘,            ‘justifyleft‘, ‘justifycenter‘, ‘justifyright‘, ‘justifyjustify‘, ‘|‘, ‘touppercase‘, ‘tolowercase‘, ‘|‘,            ‘link‘, ‘unlink‘, ‘anchor‘, ‘|‘, ‘imagenone‘, ‘imageleft‘, ‘imageright‘, ‘imagecenter‘, ‘|‘,            ‘simpleupload‘, ‘insertimage‘, ‘emotion‘, ‘scrawl‘, ‘insertvideo‘, ‘music‘, ‘attachment‘, ‘map‘, ‘gmap‘, ‘insertframe‘, ‘insertcode‘, ‘webapp‘, ‘pagebreak‘, ‘template‘, ‘background‘, ‘|‘,            ‘horizontal‘, ‘date‘, ‘time‘, ‘spechars‘, ‘snapscreen‘, ‘wordimage‘, ‘|‘,            ‘inserttable‘, ‘deletetable‘, ‘insertparagraphbeforetable‘, ‘insertrow‘, ‘deleterow‘, ‘insertcol‘, ‘deletecol‘, ‘mergecells‘, ‘mergeright‘, ‘mergedown‘, ‘splittocells‘, ‘splittorows‘, ‘splittocols‘, ‘charts‘, ‘|‘,            ‘print‘, ‘preview‘, ‘searchreplace‘, ‘help‘, ‘drafts‘        ]]

按照個人需求填寫所需就成

代碼:

  

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.