其他分享
首页 > 其他分享> > 如何获取tinyeditor编辑器里面的值

如何获取tinyeditor编辑器里面的值

作者:互联网

tinyeditor个人感觉适用于基本文本信息的编辑,即学即用。

你创建编辑器的时候:

<textarea name="input" id="input" style="width:400px; height:200px"></textarea>
var instance = new TINY.editor.edit(....);

实例如:

new TINY.editor.edit(editor,{
id:input,
width:584,
height:175,.....

在提交表单的时候或者表单验证通过之后需要调用:instance.post();

当实例对象不会被使用后,系统后自动回收的,将对象置为null, 干掉所有与对象相关的引用
注意:instance.post(); 中“instance”汉译为实例的意思,也即上方名称“editor”,在表单验证时的调用则为:editor.post();

new TINY.editor.edit(editor,{
id:input,
width:584,
height:175,.....

这样就会取到最新更新的值。

看看代码,解析一下:

需要提交的时候 必须调用 编辑器变量 也就是 edit 方法的第一个参数,的post方法来将值塞到你传入的那个 textarea 里面去, 然后再取得里面的值...

<?php
// 加载对应的css/js文件
$this->stylesheet_link_tag(
    "{$__requestdir__}static/themes/default/js",
    DOCROOT . '/static/themes/default/js',array(
        'tinyeditor/style'
    )
);
$this->js_include_tag(
    "{$__requestdir__}static/themes/default/js",
    DOCROOT . '/static/themes/default/js',array(
        'tinyeditor/core'
    )
);
?>
<script type="text/javascript">
new TINY.editor.edit('editor_<?php echo $id; ?>',{
    id:'<?php echo $id; ?>',
    width: 584,
    height: 175,
    cssclass:'te',
    controlclass:'tecontrol',
    rowclass:'teheader',
    dividerclass:'tedivider',
    controls:['bold','italic','underline','strikethrough','|','subscript','superscript','|',
              'orderedlist','unorderedlist','|','outdent','indent','|','leftalign',
              'centeralign','rightalign','blockjustify','|','unformat','|','undo','redo','n',
              'font','size','style','|','image','hr','link','unlink','|','cut','copy','paste','print'],
    footer:true,
    fonts:['Verdana','Arial','Georgia','Trebuchet MS'],
    xhtml:true,
    css: '#<?php echo $id; ?> {border:none; margin:0; padding:0; font:14px "Courier New",Verdana; border:0} #editor_<?php echo $id; ?> {cursor:text; margin:10px} ',
    bodyid:'te_c<?php echo $id; ?>',
    footerclass:'tefooter',
    toggle:{text:'source',activetext:'wysiwyg',cssclass:'toggle'},
    resize:{cssclass:'resize'}
});
window.get_<?php echo $id; ?>_content = function (){
    editor_<?php echo $id; ?>.post();
    return T$('<?php echo $id; ?>').value;
};
</script>

代码为:

editor.post();
var textAreaHtml = editor.t.value;

也可以用别的方法来得到该值

标签:__,edit,js,themes,获取,编辑器,editor,post,tinyeditor
来源: https://blog.51cto.com/u_2870645/2882445