简体   繁体   English

所见即所得(WYSIWYG)编辑器TextArea中的粗体文本

[英]WYSIWYG Editor Bold Text in TextArea

I want to be able to bold the text in the textarea when I press the bold button. 我希望能够在按下加粗按钮时将文本区域中的文本加粗。 However, when I press the bold button, the text does not change at all. 但是,当我按下粗体按钮时,文本完全不变。 Furthermore, I want the text to remain highlighted after I bold the text. 此外,我希望文本在加粗后保持高亮显示。 How would I do that? 我该怎么做?

HTML Code: 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 Code: JavaScript代码:

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

在此处输入图片说明

As per the documentation document execCommand only toggles bold on/off only for the selection. 根据文档文档execCommand仅在选择时打开/关闭粗体。 If u dont have any selection then the bold style is applied in the insertion point. 如果您没有任何选择,则将粗体样式应用于插入点。

I guess you dont need to give, 我想你不需要付出

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

Just 只是

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

will do. 会做。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM