首页 > 解决方案 > TintMCE - 单击按钮后更改文本字体大小

问题描述

单击字体按钮后,我想更改所选文本的大小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

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

标签: javascriptjquerytinymcetinymce-4

解决方案


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

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

更新代码

http://fiddle.tinymce.com/b7gaab


推荐阅读