如何使用tinymce设置textarea的宽度?

Ary*_*n G 14 tinymce

我尝试了几种方法来设置tinymce textarea的宽度.

我的第一次尝试:

height: '200px',
width: '220px'   // inside tinyMCE.init({
Run Code Online (Sandbox Code Playgroud)

在第二次尝试:

<textarea name="editorial" cols="40" rows="20" id="editorial" style="width: 40em; height: 20em"><?=$row['editorial']?></textarea>
Run Code Online (Sandbox Code Playgroud)

但是,我仍然无法按照我的要求获得宽度.

有什么想法吗?

Dai*_*Bok 22

我认为问题可能在于你的TinyMCE初始化函数中的工具栏.

试试这个例子,让我知道它是否适合你?

在您的HTML中:

<textarea name="editorial" class="test" cols="40" rows="20" id="editorial" > editorial</textarea>
Run Code Online (Sandbox Code Playgroud)

然后在JavaScript中使用这个tinyMCE.init:

    tinyMCE.init({
        // General options
        mode: "textareas",
        theme: "advanced",
        width: "300",
        height: "200",

        // Theme options
        theme_advanced_buttons1: "bold,italic,underline,|,justifyleft,justifycenter,justifyright,justifyfull",
        theme_advanced_buttons2: "",
        theme_advanced_buttons3: "",
        theme_advanced_buttons4: "",
        theme_advanced_toolbar_location: "top",
        theme_advanced_toolbar_align: "left",
        theme_advanced_resizing: false,

    // Selector
        editor_selector: "test",

});
Run Code Online (Sandbox Code Playgroud)

这对你有用吗?


小智 12

你可以用这种方式..

 tinymce.init({
selector: "textarea",   
plugins: [
            "advlist autolink autosave link image lists charmap print preview hr anchor pagebreak spellchecker",
            "searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime media nonbreaking",
            "table contextmenu directionality emoticons template textcolor paste fullpage textcolor"
    ],

    toolbar1: "bold italic underline strikethrough | alignleft aligncenter alignright alignjustify | styleselect formatselect fontselect fontsizeselect",
    toolbar2: "cut copy paste | bullist numlist | outdent indent blockquote | undo redo | anchor | forecolor backcolor",


    menubar: false,
    toolbar_items_size: 'small',

    height: "100",
    width:500,

});
Run Code Online (Sandbox Code Playgroud)

如果要设置宽度,则只需添加宽度:300

注意:请勿使用宽度为单倍或双倍:'300'或宽度:"300"