生成多个百度编辑器UEditor

项目是根要输入多天的行程,包括图片日期,于是就只能生成多个编辑器。
js根据input所填的数字,js生成占位符后,根据样式名来渲染编辑器

首先引入文件,官网直接下载就好

http://fex-team.github.io/ueditor/

<script type="text/javascript" charset="utf-8" src="/ueditor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="/ueditor/ueditor.all.min.js"></script>

js生成占位符

str_content="<tr><td width='80'>行程内容</td><td>"+"<script type='text/plain'" + " id='content_"+i+"' class='trip_editor' name='post[content_"+i+"]'></"+"script></td></tr> ";

       mycontent=String("post[content_"+i+"]");
        editorcontent=String('editorcontent'+i);
    

    };
 

      
     $("#trip_content_day").append(str);  
     var trip_editor= ".trip_editor";
     do_editor(trip_editor);
}

根据样式名渲染编辑器


function do_editor(classname){

$(classname).each(function() {
 var id = this.id;    
 var ue = UE.getEditor(id, {
     pasteplain: true, /* 纯文本粘贴 */
     autoHeightEnabled:true,/* 启用右侧滚轮,默认是true自动长高模式*/
     toolbars: [[
         'fullscreen', 'source', '|', 'undo', 'redo', '|',
         'bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript', 'removeformat', 'formatmatch', 'autotypeset', 'blockquote', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'selectall', 'cleardoc', '|',
         'rowspacingtop', 'rowspacingbottom', 'lineheight', '|',
         'customstyle', 'paragraph', 'fontfamily', 'fontsize', '|',
         'directionalityltr', 'directionalityrtl', 'indent', '|',
         'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', '|', 'touppercase', 'tolowercase', '|',
         'link', 'unlink', 'anchor', '|', 'imagenone', 'imageleft', 'imageright', 'imagecenter', '|',
         'simpleupload', 'insertimage', 'emotion', 'scrawl', 'insertvideo', 'music', 'attachment', 'map', 'gmap', 'insertframe', 'insertcode', 'webapp', 'pagebreak', 'template', 'background', '|',
         'horizontal', 'date', 'time', 'spechars', 'snapscreen', 'wordimage', '|',
         'inserttable', 'deletetable', 'insertparagraphbeforetable', 'insertrow', 'deleterow', 'insertcol', 'deletecol', 'mergecells', 'mergeright', 'mergedown', 'splittocells', 'splittorows', 'splittocols', 'charts', '|',
         'print', 'preview', 'searchreplace', 'drafts', 'help'
     ]]
 }).addOutputRule(function(root){
   // 每次编辑框获取焦点的时候都会自动插入<p><br/></p> 不需要的话我们这里可以处理一下
 // 只处理第一个空的段落,后面的段落可能是人为添加
 var firstPNode = root.getNodesByTagName("p")[0];
 firstPNode && /^\s*(<br\/>\s*)?$/.test(firstPNode.innerHTML()) && firstPNode.parentNode.removeChild(firstPNode);
 });
 console.log('ueditor for ' + id + ' init.');
});
```

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值