JAVA开发过程中遇到的问题在web页面怎样加上html在线编辑器啊???并把内容存到数据库中???
用第三方的编辑器,比如jQuery有提供
然后JS获取数据,发送HTTP给JAVA后台,后台再存入数据库
kindeditor,ckeditor都可以。。
表单直接提交到你的动态页,获取数据入库就好了
用第三方的比较方便,先用着,等以后有需要再自己开发
推荐使用UEditor
其实复制fckeditor的文件到项目目录,加入下面的代码就有编辑器了。获取编辑器数据,下面有写。很久以前做的笔记,你试下。
<script type="text/javascript">
window.onload=function(){
var oFCKeditor=new FCKeditor('ciintroduction');
oFCKeditor.BasePath="${pageContext.request.contextPath}/fckeditor/";
oFCKeditor.Width=400;
oFCKeditor.Height=200;
oFCKeditor.ToolbarSet="Basic";
oFCKeditor.ReplaceTextarea();
};
FCKeditor 配置使用 JS获取FCKeditor内容
二.FCKeditor
★FCKeditor的配置使用及JS获取FCKeditor内容
一、FCKeditor的配置使用
拷贝fckeditor文件到webroot目录下,右击文件根目录--MyEclipse--Exculde From Validation--不进行有效性验证
1._samples文件夹为例子
2.页面添加如下代码
//设置js文件路径
<script>
var editor=new FCKeditor('name'); //实例化--设置文本域名字
editor.BasePath='/guestbook/fckeditor/'; //fck根目录
editor.Height=200; //设置编辑器高度
editor.ToolbarSet='Default'; Basic:精简版 / Default:完整版 //工具栏设置
editor.Create(); //创建
</script>
自定样式:fckconfig.js
['Bold','Italic','Underline','-','JustifyLeft','JustifyCenter','JustifyRight','OrderedList','UnorderedList','-','Undo','Redo','-','Link','Unlink','-','Smiley','TextColor','BGColor','Rule'],
['Style','FontFormat','FontName','FontSize']
3.接受值:request.getParameter("name"))
4.瘦身:
一级目录: 保留文件--fckconfig.js,fckeditor.js,fckstyles.xml
二级目录editor: 删_source plugins
三级editor.lang目录: 保留zh.js zh-cn.js en.js
editor.skins目录: 删office2003,silver文件
二、更换皮肤
如果想更换皮肤:
将皮肤文件夹中的文件考入skins包:
并更改配置:
找到此行:FCKConfig.SkinPath = FCKConfig.BasePath + 'skins/default/' ;
用office2003:就将default改成office2003
还有silver等皮肤
三、图片上传路径:
PHP:
1.打开 \Public\Js\FCKeditor\editor\filemanager\connectors\语言种类\config.php文件,修改
$Config['UserFilesPath'] = '/你的项目名称/存放图片的文件夹' ;
// 如 $Config['UserFilesPath'] = '/xlmxbgCMS2TP2.0/Public/userFiles/' ;
2.在 \xlmxbgCMS2TP2.0\Public\ 目录下新建文件夹 userFiles (对应上面的例子,最好手动创建一下文件夹)
其他语言的图片、flash登上传功能暂不介绍。
四、JS获取fckeditor中内容:
// 获取编辑器中HTML内容
function getEditorHTMLContents(EditorName) {
var oEditor = FCKeditorAPI.GetInstance(EditorName);
return(oEditor.GetXHTML(true));
}
// 获取编辑器中文字内容
function getEditorTextContents(EditorName) {
var oEditor = FCKeditorAPI.GetInstance(EditorName);
return(oEditor.EditorDocument.body.innerText);
}
// 配置编辑器中内容
function SetEditorContents(EditorName, ContentStr) {
var oEditor = FCKeditorAPI.GetInstance(EditorName) ;
oEditor.SetHTML(ContentStr) ;
}
五、显示数据问题:
1.存储数据时会自动在数据后添加“,”号。
原因:在页面中有相同名的表单元素。
2.用编辑器存储的数据的特殊字符都转换为html代码,
解决:所以显示用编辑器存储的数据时:先添加一个隐藏的层,
<p>This is right content!!!</p>
然后在fckeditor的配置中添加:editor.Value=contents.innerText;
这样,以上问题都解决了。
、、、、、
火狐下js无法获取fckeditor的值
有什么办法可以在火狐下取得fckeditor里的文本或源码?
解决办法:
在火狐浏览器中没有innerText这个属性或者方法,用的是textContent。
于是修改,当ie下的时候用innerHtml火狐下的时候用textContent
修改后的代码如下
var oEditor = FCKeditorAPI.GetInstance(EditorName);//这里的EditorName是你的编辑器所产生的编辑界面名称
var foraspcn = document.all?oEditor.EditorDocument.body.innerText:oEditor.EditorDocument.body.textContent;
这样就完美解决了。
火狐下j
火狐下js无法获取fckeditor的值
s无法获取fckeditor的值