resetDemo.html 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <meta http-equiv="X-UA-Compatible" content="IE=8">
  5. <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
  6. <title>重置编辑器</title>
  7. <script type="text/javascript" charset="utf-8" src="../ueditor.config.js"></script>
  8. <script type="text/javascript" charset="utf-8" src="editor_api.js"></script>
  9. <style type="text/css">
  10. #simple {
  11. width: 1000px;
  12. border: 1px solid #ddd;
  13. }
  14. </style>
  15. </head>
  16. <body>
  17. <h2>重置编辑器和销毁编辑器示例</h2>
  18. <div class="content" id="simple"></div>
  19. <p><input type="button" onclick="simple()" value="重置编辑器内部参数"><span id="txt"></span></p>
  20. <p><input id="destroy" type="button" onclick="destroy()" value="销毁编辑器"></p>
  21. <script type="text/javascript" charset="utf-8">
  22. var editor = UE.getEditor('simple');
  23. function simple() {
  24. if(editor){
  25. editor.setContent("编辑器内部变量已经被重置!");
  26. editor.reset();
  27. }
  28. }
  29. function destroy(){
  30. editor.destroy();
  31. editor = null;
  32. clearInterval(timer);
  33. var button = document.getElementById("destroy");
  34. button.value = "重新渲染";
  35. button.onclick = function(){
  36. editor = UE.getEditor('simple');
  37. this.value="销毁编辑器";
  38. this.onclick = destroy;
  39. timer = setInterval( setMsg, 100 );
  40. }
  41. }
  42. function setMsg() {
  43. if(editor && editor.undoManger){
  44. document.getElementById( "txt" ).innerHTML = "编辑器当前保存了 <span style='color: red'> " + editor.undoManger.list.length + " </span>次操作";
  45. }
  46. }
  47. var timer = setInterval( setMsg, 100 );
  48. </script>
  49. </body>
  50. </html>