抖音开放平台Logo
开发者文档
“/”唤起搜索
控制台
  • JS API 列表
  • 基础
  • TTML
  • 网络
  • 媒体
  • 地图
  • 文件
  • 数据缓存
  • 地理位置
  • 设备
  • 画布
  • 界面
  • 交互反馈
  • tt.enableAlertBeforeUnload
  • tt.showToast
  • tt.hideToast
  • tt.showLoading
  • tt.hideLoading
  • tt.showModal
  • tt.showActionSheet
  • tt.showFavoriteGuide
  • tt.showInteractionBar
  • tt.hideInteractionBar
  • tt.disableAlertBeforeUnload
  • 导航栏
  • 菜单
  • 动画
  • 页面位置
  • 滑动返回
  • 下拉刷新
  • 键盘
  • TabBar
  • 页面导航
  • 开放接口
  • 行业开放
  • 第三方平台
  • 其它
  • 生活服务(即将废弃)
  • tt.showModal
    收藏
    我的收藏

    基础库 1.0.0 开始支持本方法,这是一个异步方法。

    显示模态弹窗。用于同步用户重要信息,并要求用户进行确认,或执行特定操作以决策下一步骤。

    前提条件无
    业务背景无
    使用限制无
    注意事项

    输入参数的 title 和 content 不可同时为空。

    支持沙盒
    否
    相关教程无

    语法

    tt.showModal(options)

    参数说明

    options 为 object 类型,属性如下:

    属性名类型默认值必填说明最低支持版本
    titlestring否
    标题,字数限制为两行
    1.0.0
    contentstring否
    内容,没有字数限制,超长会产生滚动条
    1.0.0
    confirmTextstring确定否
    确定按钮的文案,最多 4 个字符
    1.0.0
    showCancelbooleantrue否
    是否显示取消按钮
    1.0.0
    cancelTextstring取消否
    取消按钮的文案,最多 4 个字符
    1.0.0
    confirmColorstring#F85959否
    确认按钮的文字颜色,必须是 16 进制格式的颜色字符串
    2.62.0
    cancelColorstring#000000否
    取消按钮的文字颜色,必须是 16 进制格式的颜色字符串
    2.62.0
    editablebooleanfalse否
    是否显示输入框
    2.62.0
    placeholderTextstring否
    显示输入框时的提示文本
    2.62.0
    imageSrcstring否

    弹出的模态框里展示的图片,只支持宽高比为 2:1 的图片,只支持小程序包内静态资源图片或 ttfile 开头(如通过 tt.downloadFile 或 tt.chooseImage 获取的临时图片地址)的本地图片,不支持网络图片。图片类型 imageSrc 的合法值

    2.74.0
    successfunction否
    接口调用成功的回调函数
    1.0.0
    failfunction否
    接口调用失败的回调函数
    1.0.0
    completefunction否
    接口调用结束的回调函数(调用成功、失败都会执行)
    1.0.0

    imageSrc 参数说明

    值

    说明

    最低支持版本

    JPG

    .jpg 图片格式

    2.74.0

    PNG

    .png 图片格式

    2.74.0

    SVG

    .svg 图片格式

    2.74.0

    WEBP

    .webp 图片格式

    2.74.0

    回调成功

    object 类型,属性如下:

    属性名类型说明最低支持版本
    errMsgstring
    "showModal:ok"
    1.0.0
    confirmboolean
    是否点击了确定按钮
    1.0.0
    cancelboolean
    是否点击了取消按钮
    1.0.0
    contentstring
    editable 为 true 时,用户输入的文本
    1.0.0

    回调失败

    object 类型,属性如下:

    属性名类型说明最低支持版本
    errMsgstring
    "showModal:fail" + 详细错误信息
    1.0.0

    错误码

    errorCodeerrMsgerrorType说明最低支持版本
    102499showModal:fail Title and content can't be both emptyD
    参数校验错误
    1.0.0
    102491showModal:fail Internal error: Activity is null,showModal:fail Internal error: no api callbackF
    小程序框架内部错误,有需要请创建工单咨询
    1.0.0
    102401showModal:fail The image aspect ratio must be 2:1D
    图片宽高比必须为 2:1
    1.0.0
    102402showModal:fail imageSrc is invalidD
    imageSrc属性无效
    1.0.0
    102403showModal:fail unsupported image typeD
    不支持图片类型
    1.0.0

    扫码体验

    请使用字节宿主APP扫码

    代码示例