标签:判断 let click tco div public 点击 dom ati
删除编辑器" onclick="deleteEditor()"/>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<!--<meta http-equiv="X-UA-Compatible" content="IE=8">-->
<title>完整demo</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<script type="text/javascript" charset="utf-8">
window.UEDITOR_HOME_URL = "/ueditor/"; //UEDITOR_HOME_URL、config、all这三个顺序不能改变
</script>
<script type="text/javascript" charset="utf-8" src="./ueditor/editor_config.js"></script>
<!--使用版-->
<!--<script type="text/javascript" charset="utf-8" src="../editor_all.js"></script>-->
<!--开发版-->
<script type="text/javascript" charset="utf-8" src="./ueditor/editor_all.js">
</script>
<style type="text/css">
.clear {
clear: both;
}
</style>
</head>
<body>
<div>
<script id="editor" type="text/plain" style="width:1076px;" >这里可以书写,编辑器的初始内容</script>
</div>
<div class="clear"></div>
<div id="btns">
<div >
<input type="button" value="获得整个html的内容" onclick="getAllHtml()">
<input type="button" value="获得内容" onclick="getContent()">
<input type="button" value="写入内容" onclick="setContent()">
<input type="button" value="获得纯文本" onclick="getContentTxt()">
<input type="button" value="获得带格式的纯文本" onclick="getPlainTxt()">
<input type="button" value="判断是否有内容" onclick="hasContent()">
<input type="button" value="使编辑器获得焦点" onclick="setFocus()">
</div>
<div >
<input type="button" value="获得当前选中的文本" onclick="getText()"/>
<input type="button" value="删除编辑器" onclick="deleteEditor()"/>
<input id="enable" type="button" value="可以编辑" onclick="setEnabled()"/>
<input type="button" value="不可编辑" onclick="setDisabled()"/>
<input type="button" value="隐藏编辑器" onclick=" UE.getEditor(‘editor‘).setHide()"/>
<input type="button" value="显示编辑器" onclick=" UE.getEditor(‘editor‘).setShow()"/>
</div>
</div>
<div >
<input type="button" value="创建编辑器" onclick="createEditor()"/>
<input type="button" value="删除编辑器" onclick="deleteEditor()"/>
</div>
</body>
<script type="text/javascript">
//实例化编辑器
UE.getEditor(‘editor‘);
function createEditor(){
enableBtn();
UE.getEditor(‘editor‘)
}
function getAllHtml() {
alert( UE.getEditor(‘editor‘).getAllHtml() )
}
function getContent() {
var arr = [];
arr.push( "使用editor.getContent()方法可以获得编辑器的内容" );
arr.push( "内容为:" );
arr.push( UE.getEditor(‘editor‘).getContent() );
alert( arr.join( "\n" ) );
}
function getPlainTxt() {
var arr = [];
arr.push( "使用editor.getPlainTxt()方法可以获得编辑器的带格式的纯文本内容" );
arr.push( "内容为:" );
arr.push( UE.getEditor(‘editor‘).getPlainTxt() );
alert( arr.join( ‘\n‘ ) )
}
function setContent() {
var arr = [];
arr.push( "使用editor.setContent(‘欢迎使用ueditor‘)方法可以设置编辑器的内容" );
UE.getEditor(‘editor‘).setContent( ‘欢迎使用ueditor‘ );
alert( arr.join( "\n" ) );
}
function setDisabled() {
UE.getEditor(‘editor‘).setDisabled( ‘fullscreen‘ );
disableBtn( "enable" );
}
function setEnabled() {
UE.getEditor(‘editor‘).setEnabled();
enableBtn();
}
function getText() {
//当你点击按钮时编辑区域已经失去了焦点,如果直接用getText将不会得到内容,所以要在选回来,然后取得内容
var range = UE.getEditor(‘editor‘).selection.getRange();
range.select();
var txt = UE.getEditor(‘editor‘).selection.getText();
alert( txt )
}
function getContentTxt() {
var arr = [];
arr.push( "使用editor.getContentTxt()方法可以获得编辑器的纯文本内容" );
arr.push( "编辑器的纯文本内容为:" );
arr.push( UE.getEditor(‘editor‘).getContentTxt() );
alert( arr.join( "\n" ) );
}
function hasContent() {
var arr = [];
arr.push( "使用editor.hasContents()方法判断编辑器里是否有内容" );
arr.push( "判断结果为:" );
arr.push( UE.getEditor(‘editor‘).hasContents() );
alert( arr.join( "\n" ) );
}
function setFocus() {
UE.getEditor(‘editor‘).focus();
}
function deleteEditor() {
disableBtn();
UE.getEditor(‘editor‘).destroy();
}
function disableBtn( str ) {
var div = document.getElementByIdx_x( ‘btns‘ );
var btns = domUtils.getElementsByTagName_r( div, "input" );
for ( var i = 0, btn; btn = btns[i++]; ) {
if ( btn.id == str ) {
domUtils.removeAttributes( btn, ["disabled"] );
} else {
btn.setAttribute( "disabled", "true" );
}
}
}
function enableBtn() {
var div = document.getElementByIdx_x( ‘btns‘ );
var btns = domUtils.getElementsByTagName_r( div, "input" );
for ( var i = 0, btn; btn = btns[i++]; ) {
domUtils.removeAttributes( btn, ["disabled"] );
}
}
</script>
</html>
来源:http://blog.sina.com.cn/s/blog_6790fbba0101dzzj.html
标签:判断 let click tco div public 点击 dom ati
原文地址:http://www.cnblogs.com/kongxc/p/6623370.html