TintMCE-单击按钮后更改文本字体大小

时间:2018-12-20 08:16:13

标签: javascript jquery tinymce tinymce-4

Change Font中单击字体按钮后,我想更改所选文本的大小: 但是我在使用该行后并没有改变:

editor.execCommand("fontSize", false, e.data.source)

以下是带有小提琴的代码:

<script type="text/javascript">
tinymce.init({
    selector: "textarea",
    plugins: [
        "advlist autolink lists link image charmap print preview anchor",
        "searchreplace visualblocks code fullscreen",
        "insertdatetime media table contextmenu paste"
    ],
    toolbar: "wrapselection | code | insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image",
    setup: function (editor) {
       editor.addButton('wrapselection', {
          text: 'Change Font',
          icon: false,
          onclick: function () {


                    editor.windowManager.open({
                    title: 'Enter Font Size',
                    body: [
                        {type: 'textbox', name: 'source', label: 'Font Size'}
                    ],
                    onsubmit: function(e) {
                        alert(e.data.source);
                        editor.focus();
                        editor.execCommand("fontSize", false, e.data.source);

                    }
                });


          }
       });
    }

});
</script>

<form method="post" action="dump.php">
    <textarea name="content">This is content in the editor</textarea>
</form>

http://fiddle.tinymce.com/a7gaab

在用户单击大小后如何更改字体大小?

1 个答案:

答案 0 :(得分:1)

只需在警报消息之后添加以下代码行

editor.getBody().style.fontSize = e.data.source + 'px';

更新的代码

http://fiddle.tinymce.com/b7gaab

相关问题