微信小程序API 富文本


本文整理自网络,侵删。

EditorContext

基础库 2.7.0 开始支持,低版本需做兼容处理。

EditorContext 实例,可通过 wx.createSelectorQuery 获取。

EditorContext 通过 id 跟一个 editor 组件绑定,操作对应的 editor 组件。

方法:

EditorContext.blur(Object object)

基础库 2.8.3 开始支持,低版本需做兼容处理。

编辑器失焦,同时收起键盘。

参数

Object object

属性类型默认值必填说明
successfunction接口调用成功的回调函数
failfunction接口调用失败的回调函数
completefunction接口调用结束的回调函数(调用成功、失败都会执行)


EditorContext.clear(Object object)

基础库 2.7.0 开始支持,低版本需做兼容处理。

清空编辑器内容

参数

Object object

属性类型默认值必填说明
successfunction接口调用成功的回调函数
failfunction接口调用失败的回调函数
completefunction接口调用结束的回调函数(调用成功、失败都会执行)


EditorContext.format(string name, string value)

基础库 2.7.0 开始支持,低版本需做兼容处理。

修改样式

参数

string name

属性

string value

支持设置的样式列表

namevalueverson
bold2.7.0
italic2.7.0
underline2.7.0
strike2.7.0
ins2.7.0
scriptsub / super2.7.0
headerH1 / H2 / h3 / H4 / h5 / H62.7.0
alignleft / center / right / justify2.7.0
directionrtl2.7.0
indent-1 / +12.7.0
listordered / bullet / check2.7.0
colorhex color2.7.0
backgroundColorhex color2.7.0
margin/marginTop/marginBottom/marginLeft/marginRightcss style2.7.0
padding/paddingTop/paddingBottom/paddingLeft/paddingRightcss style2.7.0
font/fontSize/fontStyle/fontVariant/fontWeight/fontFamilycss style2.7.0
lineHeightcss style2.7.0
letterSpacingcss style2.7.0
textDecorationcss style2.7.0
textIndentcss style2.8.0
wordWrapcss style2.10.2
wordBreakcss style2.10.2
whiteSpacecss style2.10.2

对已经应用样式的选区设置会取消样式。css style 表示 css 中规定的允许值。


EditorContext.getContents(Object object)

基础库 2.7.0 开始支持,低版本需做兼容处理。

获取编辑器内容

参数

Object object

属性类型默认值必填说明
successfunction接口调用成功的回调函数
failfunction接口调用失败的回调函数
completefunction接口调用结束的回调函数(调用成功、失败都会执行)

object.success 回调函数

参数
Object res
属性类型说明
htmlstring带标签的HTML内容
textstring纯文本内容
deltaObject表示内容的delta对象


EditorContext.getSelectionText(Object object)

基础库 2.10.2 开始支持,低版本需做兼容处理。

获取编辑器已选区域内的纯文本内容。当编辑器失焦或未选中一段区间时,返回内容为空。

参数

Object object

属性类型默认值必填说明
successfunction接口调用成功的回调函数
failfunction接口调用失败的回调函数
completefunction接口调用结束的回调函数(调用成功、失败都会执行)

object.success 回调函数

参数
Object res
属性类型说明
textstring纯文本内容


EditorContext.insertDivider(Object object)

基础库 2.7.0 开始支持,低版本需做兼容处理。

插入分割线

参数

Object object

属性类型默认值必填说明
successfunction接口调用成功的回调函数
failfunction接口调用失败的回调函数
completefunction接口调用结束的回调函数(调用成功、失败都会执行)


EditorContext.insertImage(Object object)

基础库 2.7.0 开始支持,低版本需做兼容处理。

插入图片。

阅读剩余部分

相关阅读 >>

微信小程序开发教程手册文档

微信小程序云开发api get方法

微信小程序api 绘图createcirculargradient(创建圆形渐变)

微信小程序api 绘图介绍(如何在canvas上画图)

微信小程序api nfc-nfcadapter标签

微信小程序 插件功能页

微信小程序api nfc-isodep标签

微信小程序内容组件 text(文本)

微信小程序api 音频-inneraudiocontext对象

微信小程序api 性能测速上报

更多相关阅读请进入《微信小程序》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...