WYSIWYG редактор, выделенный жирным шрифтом в TextArea - PullRequest
0 голосов
/ 13 июня 2018

Я хочу иметь возможность полужирного текста в текстовой области, когда я нажимаю кнопку полужирного.Тем не менее, когда я нажимаю кнопку жирным шрифтом, текст не меняется вообще.Кроме того, я хочу, чтобы текст оставался выделенным после полужирного текста.Как бы я это сделал?

HTML-код:

 <div class="col-md-8">
                            <input type = "button" value = "B" onclick = "bold()">
                            <input type = "button" value = "I" onclick = "italics()">
                            <input type = "button" value = "U" onclick = "underline()">
                            <input type = "button" value = "Size" onclick = "fontsize()">
                            <input type = "button" value = "Color" onclick = "fontcolor()">
                            <input type = "button" value = "Highlight" onclick = "highlight()">
                            <input type = "button" value = "Link" onclick = "link()">
                            <input type = "button" value = "Strike" onclick = "strikethrough()">
                            <input type = "button" value = "Exp" onclick = "exponent()">
                            <input type = "button" value = "Sub" onclick = "subscript()">
                            <input type = "button" value = "Bullet" onclick = "bullet()">
                            <input type = "button" value = "List" onclick = "list()">
                            <input type = "button" value = "Space" onclick = "spacing()">
                            <br><br>

                        <textarea name = "content" id = "content" style = "width: 720; height: 400;" ></textarea>

Код Javascript:

function bold(){
    content.document.execCommand('bold', false, null);
}

1 Ответ

0 голосов
/ 13 июня 2018

enter image description here

Согласно документу документации execCommand включает / выключает только выделение жирным шрифтом только для выделения.Если у вас нет выбора, то в точке вставки применяется жирный стиль.

Я думаю, вам не нужно давать,

content.document.execCommand('bold',false,null);

Просто

document.execCommand('bold',false,null);

будет делать.

...