kindEditor PHP示例
文件自身调用
/*此处注意,上传文件是,请先创建对应的上传文件目录,配置在upload_json.php中,建议同时修改file_manager_json.php中相关配置*/
/*获取form表单传值*/
<?php
$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>
更多帮助信息,参见http://kindeditor.net/docs/
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。