小程序开放平台

文档中心
基础
界面
交互
showLoading
hideLoading
showToast
hideToast
showActionSheet
showModal
下拉刷新
动画
字体
网络
数据缓存
媒体
位置
开放接口
设备
XHSML
性能
文件
数据分析
画布

xhs.showModal

开发
>
JS API
>
界面
>
交互
>
showModal
>
更新时间:2024-11-28 20:08:04

以Promise风格调用: 支持

显示消息提示框

参数

Object object

属性
类型
默认值
必填
说明
titlestring提示的标题
contentstring提示的内容
showCancelbooleantrue是否显示取消按钮
cancelTextstring取消取消按钮的文字,最多 4 个字符
cancelColorstring#333333取消按钮的文字颜色,必须是 16 进制格式的颜色字符串
confirmTextstring确定确认按钮的文字,最多 4 个字符
confirmColorstring#FF2442确认按钮的文字颜色,必须是 16 进制格式的颜色字符串
editablebooleanfalse是否显示输入框
placeholderTextstring显示输入框时的提示文本
successfunction接口调用成功的回调函数
failfunction接口调用失败的回调函数
completefunction接口调用结束的回调函数(调用成功、失败都会执行)

object.success 回调函数

属性
类型
说明
errMsgstring
cancelboolean是否取消
confirmboolean是否确认

实例代码

xhs.showModal({
  title: '提示',
  content: '这是一个模态弹窗',
  success (res) {
    if (res.confirm) {
      console.log('用户点击确定')
    } else if (res.cancel) {
      console.log('用户点击取消')
    }
  }
})