kindEditor PHP示例

文件自身調用 php

/*此處注意,上傳文件是,請先建立對應的上傳文件目錄,配置在upload_json.php中,建議同時修改file_manager_json.php中相關配置*/ css

/*獲取form表單傳值*/ html

<?php json

    $htmlData = '';
    if (!empty($_POST['content'])) {
        if (get_magic_quotes_gpc()) {
            $htmlData = stripslashes($_POST['content']);
        } else {
            $htmlData = $_POST['content'];
        }
    }
    echo $htmlData;
?>

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>

    <script charset="utf-8" src="kindeditor-all-min.js"></script>
    <script charset="utf-8" src="zh-CN.js"></script>
    <script>
        var editor;
        KindEditor.ready(function(K) {
            editor = K.create('textarea[name="content"]', {
                cssPath : './plugins/code/prettify.css',
                uploadJson : './php/upload_json.php',
                fileManagerJson : './php/file_manager_json.php',
                allowFileManager : true,
                afterCreate : function() {
                    var self = this;
                    K.ctrl(document, 13, function() {                <!--指定函數綁定到ctrl + [key]組合鍵事件上-->
                        self.sync();
                        K('form[name=example]')[0].submit();
                    });
                    K.ctrl(self.edit.doc, 13, function() {
                        self.sync();
                        K('form[name=example]')[0].submit();
                    });
                }
            });
            <!--常方法-->
            K('input[name=getHtml]').click(function(e) {
                alert(editor.html());
            });
            K('input[name=isEmpty]').click(function(e) {
                alert(editor.isEmpty());
            });
            K('input[name=getText]').click(function(e) {
                alert(editor.text());
            });
            K('input[name=selectedHtml]').click(function(e) {
                alert(editor.selectedHtml());
            });
            K('input[name=setHtml]').click(function(e) {
                editor.html('<h3>Hello KindEditor</h3>');
            });
            K('input[name=setText]').click(function(e) {
                editor.text('<h3>Hello KindEditor</h3>');
            });
            K('input[name=insertHtml]').click(function(e) {
                editor.insertHtml('<strong>插入HTML</strong>');
            });
            K('input[name=appendHtml]').click(function(e) {
                editor.appendHtml('<strong>添加HTML</strong>');
            });
            K('input[name=clear]').click(function(e) {
                editor.html('');
            });
        });
    </script>
</head>
<body>
    <form action="kindeditor.php" name="example" method="post">
    <textarea id="editor_id" name="content" style="width:700px;height:300px;">
    </textarea>
    <p>
        <input type="button" name="getHtml" value="取得HTML" />
        <input type="button" name="isEmpty" value="判斷是否爲空" />
        <input type="button" name="getText" value="取得文本(包含img,embed)" />
        <input type="button" name="selectedHtml" value="取得選中HTML" />
        <br />
        <br />
        <input type="button" name="setHtml" value="設置HTML" />
        <input type="button" name="setText" value="設置文本" />
        <input type="button" name="insertHtml" value="插入HTML" />
        <input type="button" name="appendHtml" value="添加HTML" />
        <input type="button" name="clear" value="清空內容" />
        <input type="reset" name="reset" value="Reset" />
    </p>
    <input type="submit" name="button" value="提交內容" /> (提交快捷鍵: Ctrl + Enter)
    </form>
</body>

</html> app


更多幫助信息,參見http://kindeditor.net/docs/ 函數

相關文章
相關標籤/搜索