1 <input type="hidden" id="id" value="${fileinfo.id}" name="id"> 2 <textarea name="fileHtml" id="fileHtml" rows="10" cols="80"> 3 ${fileinfo.fileHtml} 4 </textarea> 5 <div> 6 <button id="ensure" onclick="editSubmit()">保存</button> 7 <button id="cancel" onclick="close()">取消</button> 8 </div> 9 <script> 10 CKEDITOR.replace('fileHtml');//将相应的控件替换成编辑器代码 11 </script> 12 <script> 13 close = function() { 14 parent.layer.close(parent.layer.getFrameIndex(window.name)); //先得到当前iframe层的索引,再执行关闭 15 } 16 editSubmit = function() { 17 $.ajax({ 18 url : "/cbom/fileinfo/update", //处理页面的路径 19 type : "post", 20 dataType : "json", 21 data : { 22 "id" : $("#id").val(), 23 "fileHtml" : CKEDITOR.tools.htmlEncode(CKEDITOR.instances.fileHtml.getData())// 24 }, 25 success : function(data) { 26 Sys.success("修改成功!"); 27 window.parent.Fileinfo.table.refresh(); 28 close(); 29 }, 30 error : function(data) { 31 Sys.error("修改失败!" + data.responseJSON.message + "!"); 32 } 33 }); 34 } 35 </script>
利用CKEDITOR.tools.htmlEncode()对获取到的html源码编码,替换字符串中的特殊HTML字符,再传递到后台,这样就不会丢失了。