为了方便记录防止代码丢失特此记录
对话框超时默认选择固定选项
{
// 对话框超时默认选择
//
let a = undefined
let b = undefined
new Promise(function (resvole, reject) {
a = dialogs.build({
title: "请选择",
content: "",
positive: "选项A",
negative: "选项B"
}).on("positive", () => {
resvole()
alert("选项A");
}).on("negative", () => {
resvole()
alert("选项B");
}).on('cancel', function () {
alert('按错地方了,默认选项B')
resvole()
})
//创建定时器
b = setTimeout(function () {
reject()
}, 2000)
a.show()
}).then(function () {
//已选择,清空定时器
clearTimeout(b)
}).catch(function () {
alert("超时,默认选项B");
a.dismiss()
})
}
本文介绍了如何在JavaScript中实现对话框超时后自动选择预设选项,通过Promise和setTimeout来管理超时行为,并确保在用户操作延迟或超时时提供明确反馈。
1221

被折叠的 条评论
为什么被折叠?



