首页 > 解决方案 > 使用tinymce(tinymce-angular)专注于textarea

问题描述

我正在使用带有角度的tinymce(tinymce-angular)。tinymce 的版本好像是 5.4.1。

页面上有几个编辑器字段/文本区域,我想关注第一个页面加载。那可能吗?在 html 或 ts 文件中。

这就是我初始化编辑器的方式:

环形...

 <editor [(ngModel)]="map.get(item.id).item"
                        [ngModelOptions]="{standalone: true}"
                        (onBlur)="itemChanged(item.id)"
                        [initialValue]="map.get(item.id).item"
                        [init]="{plugins: 'link',
          menubar: false,
          toolbar:false,
          base_url: './assets/tinymce',
          suffix: '.min',
          branding: false,
          elementpath: false,
          statusbar:false,
          height:100,
          tabindex:0,
          auto_resize:true,
          placeholder: 'Type here please',
          autoresize_bottom_margin: 10}">
                </editor>

标签: angulartinymce-5

解决方案


这种代码似乎有效:

   var currentItem = document.getElementById(divid);
              var editors = currentItem.getElementsByTagName('iframe');
              if (editors !== undefined && editors.length > 0) {
                var editor = editors[0];
                var body = editor.contentDocument.getElementsByTagName('body');
                if (body !== undefined && body.length > 0) {
                  body[0].focus();
                }
              }

推荐阅读