index.html 4.2 KB
<!doctypehtml><title>完整demo</title><meta content="text/html;charset=utf-8"http-equiv=Content-Type><script charset=utf-8 src=ueditor.config.js></script><script charset=utf-8 src=ueditor.all.min.js></script><script charset=utf-8 src=lang/zh-cn/zh-cn.js></script><style>div{width:100%}</style><div><h1>完整demo</h1><script id=editor style=width:1024px;height:500px type=text/plain></script></div><div id=btns><div><button onclick=getAllHtml()>获得整个html的内容</button> <button onclick=getContent()>获得内容</button> <button onclick=setContent()>写入内容</button> <button onclick=setContent(!0)>追加内容</button> <button onclick=getContentTxt()>获得纯文本</button> <button onclick=getPlainTxt()>获得带格式的纯文本</button> <button onclick=hasContent()>判断是否有内容</button> <button onclick=setFocus()>使编辑器获得焦点</button> <button onmousedown=isFocus(event)>编辑器是否获得焦点</button> <button onmousedown=setblur(event)>编辑器失去焦点</button></div><div><button onclick=getText()>获得当前选中的文本</button> <button onclick=insertHtml()>插入给定的内容</button> <button onclick=setEnabled() id=enable>可以编辑</button> <button onclick=setDisabled()>不可编辑</button> <button onclick='UE.getEditor("editor").setHide()'>隐藏编辑器</button> <button onclick='UE.getEditor("editor").setShow()'>显示编辑器</button> <button onclick='UE.getEditor("editor").setHeight(300)'>设置高度为300默认关闭了自动长高</button></div><div><button onclick=getLocalData()>获取草稿箱内容</button> <button onclick=clearLocalData()>清空草稿箱</button></div></div><div><button onclick=createEditor()>创建编辑器</button> <button onclick=deleteEditor()>删除编辑器</button></div><script>var ue=UE.getEditor("editor");function isFocus(t){alert(UE.getEditor("editor").isFocus()),UE.dom.domUtils.preventDefault(t)}function setblur(t){UE.getEditor("editor").blur(),UE.dom.domUtils.preventDefault(t)}function insertHtml(){var t=prompt("插入html代码","");UE.getEditor("editor").execCommand("insertHtml",t)}function createEditor(){enableBtn(),UE.getEditor("editor")}function getAllHtml(){alert(UE.getEditor("editor").getAllHtml())}function getContent(){var t=[];t.push("使用editor.getContent()方法可以获得编辑器的内容"),t.push("内容为:"),t.push(UE.getEditor("editor").getContent()),alert(t.join("\n"))}function getPlainTxt(){var t=[];t.push("使用editor.getPlainTxt()方法可以获得编辑器的带格式的纯文本内容"),t.push("内容为:"),t.push(UE.getEditor("editor").getPlainTxt()),alert(t.join("\n"))}function setContent(t){var e=[];e.push("使用editor.setContent('欢迎使用ueditor')方法可以设置编辑器的内容"),UE.getEditor("editor").setContent("欢迎使用ueditor",t),alert(e.join("\n"))}function setDisabled(){UE.getEditor("editor").setDisabled("fullscreen"),disableBtn("enable")}function setEnabled(){UE.getEditor("editor").setEnabled(),enableBtn()}function getText(){UE.getEditor("editor").selection.getRange().select();var t=UE.getEditor("editor").selection.getText();alert(t)}function getContentTxt(){var t=[];t.push("使用editor.getContentTxt()方法可以获得编辑器的纯文本内容"),t.push("编辑器的纯文本内容为:"),t.push(UE.getEditor("editor").getContentTxt()),alert(t.join("\n"))}function hasContent(){var t=[];t.push("使用editor.hasContents()方法判断编辑器里是否有内容"),t.push("判断结果为:"),t.push(UE.getEditor("editor").hasContents()),alert(t.join("\n"))}function setFocus(){UE.getEditor("editor").focus()}function deleteEditor(){disableBtn(),UE.getEditor("editor").destroy()}function disableBtn(t){for(var e,o=document.getElementById("btns"),n=UE.dom.domUtils.getElementsByTagName(o,"button"),i=0;e=n[i++];)e.id==t?UE.dom.domUtils.removeAttributes(e,["disabled"]):e.setAttribute("disabled","true")}function enableBtn(){for(var t,e=document.getElementById("btns"),o=UE.dom.domUtils.getElementsByTagName(e,"button"),n=0;t=o[n++];)UE.dom.domUtils.removeAttributes(t,["disabled"])}function getLocalData(){alert(UE.getEditor("editor").execCommand("getlocaldata"))}function clearLocalData(){UE.getEditor("editor").execCommand("clearlocaldata"),alert("已清空草稿箱")}</script>