【问题标题】:WYSIWYG Editor Bold Text in TextArea所见即所得编辑器 TextArea 中的粗体文本
【发布时间】:2018-06-13 03:55:45
【问题描述】:

当我按下粗体按钮时,我希望能够将文本区域中的文本加粗。但是,当我按下粗体按钮时,文本根本没有改变。此外,我希望文本在我加粗文本后保持突出显示。我该怎么做?

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);
}

【问题讨论】:

  • 你设置了document.designMode = "on" 吗?

标签: javascript html wysiwyg text-editor


【解决方案1】:

根据文档文档 execCommand 仅在选择时打开/关闭粗体。如果您没有任何选择,则在插入点应用粗体样式。

我猜你不需要付出,

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

只是

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

会的。

【讨论】:

    猜你喜欢
    • 2016-07-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-02
    • 1970-01-01
    相关资源
    最近更新 更多