如何将样式应用于字符串的选定字符 - AngularJS
How is styling being applied on selected characters of the string- AngularJS
我在 this plunkr 中遇到了富文本编辑器,想知道代码究竟是如何理解特定 element
必须用 bold
样式装饰的?
$container.html()
在 console
中显示了正确的样式,但它如何知道为样式选择了字符串的哪一部分?
所以那个 plunkr 正在使用一个名为 contenteditable
的 HTML5 功能。简而言之,此属性将 html 元素(通常是 div)转换为类似于文本区域的元素,但您正在编辑页面上的实际 html。
至于选定的样式,Bold 按钮使用 Document.execCommand
将命令应用于当前选择。
这里有一个关于开始使用 contenteditable 和 execCommand 的教程:https://code.tutsplus.com/tutorials/create-a-wysiwyg-editor-with-the-contenteditable-attribute--cms-25657。希望对您有所帮助。
PS 我更新了您评论的另一个问题中的 link。
我在 this plunkr 中遇到了富文本编辑器,想知道代码究竟是如何理解特定 element
必须用 bold
样式装饰的?
$container.html()
在 console
中显示了正确的样式,但它如何知道为样式选择了字符串的哪一部分?
所以那个 plunkr 正在使用一个名为 contenteditable
的 HTML5 功能。简而言之,此属性将 html 元素(通常是 div)转换为类似于文本区域的元素,但您正在编辑页面上的实际 html。
至于选定的样式,Bold 按钮使用 Document.execCommand
将命令应用于当前选择。
这里有一个关于开始使用 contenteditable 和 execCommand 的教程:https://code.tutsplus.com/tutorials/create-a-wysiwyg-editor-with-the-contenteditable-attribute--cms-25657。希望对您有所帮助。
PS 我更新了您评论的另一个问题中的 link。