新手问题 [已解决] 在同一个页面使用多个富文本编辑器 ( Simditor),会出错

chairy11 · 2015年01月14日 · 最后由 ROR-Eason 回复于 2017年09月29日 · 9620 次阅读

问题


使用了开源的 Tower 的富文本编辑器 Simditor。 因为某种蛋疼的原因,在同一个表单,有多个 textarea,希望是每个 textarea 都对应着一个富文本编辑器。

结果,虽然的确给每个 textarea 加了一个 Simditor,但同时也会出现奇怪的多个 textarea 在每一个 Simditor 里面。这是为什么呢?

是不是 js 写得不对?我现在写的是:

 editor = new Simditor(
  textarea: $('.rich_text_editor')
  upload: true
  toolbar: ['bold', 'italic', 'underline', '|', 'ol', 'ul', 'blockquote', 'code', '|', 'link', 'image', '|', 'indent', 'outdent', '|', 'hr', 'table']
)

@zchar

解决方案(由@hz_qiuyuanxin 提供)

$(".rich_text_editor").each (index, dom) ->
    new Simditor(
      textarea: $(dom)
      upload: true
      toolbar: ['bold', 'italic', 'underline', '|', 'ol', 'ul', 'blockquote', 'code', '|', 'link', 'image', '|', 'indent', 'outdent', '|', 'hr', 'table']
    )

谢谢各位:)

没用过 Simditor,不过你试试这样,使用迭代的方式对每一个 textarea 进行初始化

$(".rich_text_editor").each(function(index, dom){
    new Simditor({
      textarea: $(dom),
      // ....
    })
});

你的 textarea class 一样的吧,分开绑试试

editor1 = new Simditor(
  textarea: $('.rich_text_editor')
  upload: true
  toolbar: ['bold', 'italic', 'underline', '|', 'ol', 'ul', 'blockquote', 'code', '|', 'link', 'image', '|', 'indent', 'outdent', '|', 'hr', 'table']
)
editor2 = new Simditor(
  textarea: $('.rich_text_editor')
  upload: true
  toolbar: ['bold', 'italic', 'underline', '|', 'ol', 'ul', 'blockquote', 'code', '|', 'link', 'image', '|', 'indent', 'outdent', '|', 'hr', 'table']
)

定义两个试试

你好,请问该怎么添加图片上传这个功能?

需要 登录 后方可回复, 如果你还没有账号请 注册新账号