您的位置:首页 > 游戏 > 游戏 > 国外优秀网页设计作品_金戈西地那非片能延时多久_2024年最新时事新闻_百度seo新算法

国外优秀网页设计作品_金戈西地那非片能延时多久_2024年最新时事新闻_百度seo新算法

2025/8/21 0:31:09 来源:https://blog.csdn.net/2401_87008233/article/details/146483713  浏览:    关键词:国外优秀网页设计作品_金戈西地那非片能延时多久_2024年最新时事新闻_百度seo新算法
国外优秀网页设计作品_金戈西地那非片能延时多久_2024年最新时事新闻_百度seo新算法

clearInterval

        clearInterval(number intervalID)

        取消由setInterval设置的定时器。

参数:

参数类型必填描述
intervalIDnumber取消定时器的ID 。

示例:

clearInterval(111);

setInterval

        setInterval(function callback, number delay, any rest)

        设定一个定时器。

参数:

参数类型必填描述
callbackfunction回调函数 。
delaynumber

执行回调函数的时间间隔,单位ms。

兼容数字的字符串,不传、传入非数字的字符串或其它类型,默认按0处理。

restanyparam1, param2, ...等附加参数,它们会作为参数传递给回调函数。

示例: 

setInterval(() => {console.log('setInterval success');
}, 3000, 'param1', 'param2');

clearTimeout

        clearTimeout(number timeoutID)

        取消由 setTimeout 设置的定时器 。

参数:

参数类型必填描述
timeoutIDnumber取消定时器的ID 。

示例:

clearTimeout(111);

setTimeout

        setTimeout(function callback, number delay, any rest)

        设定一个定时器。

参数:

参数类型必填描述
callbackfunction回调函数 。
delaynumber

执行回调函数之间的时间间隔,单位ms。

兼容数字的字符串,不传、传入非数字的字符串或其它类型,默认按0处理。

restanyparam1, param2, ...等附加参数,它们会作为参数传递给回调函数。

示例:

setTimeout(() => {console.log('setTimeout success');
}, 3000, 'param1', 'param2');

代码演示:

@Entry
@Component
struct LoginDemo {@State time: number = 0build() {Column() {this.titleBuilder()TextInput({ placeholder: '请输入手机号' }).backgroundColor(Color.White).padding({ left: 0, top: 20, bottom: 20 }).placeholderColor('#ccc')Divider()Row() {TextInput({ placeholder: '请输入验证码' }).backgroundColor(Color.White).padding({ left: 0, top: 20, bottom: 20 }).placeholderColor('#ccc').layoutWeight(1)Text(this.time == 0 ? '发送验证码' : `${this.time}秒后获取`).fontSize(14).fontColor(Color.Gray).onClick(() => {// 避免重复点击if (this.time != 0) {// return 会阻断后续代码执行return}// 延迟获取验证码setTimeout(() => {const code = Math.floor(1000 + Math.random() * 9000)// console.log('code:', code)AlertDialog.show({message: code.toString()})}, 2000)// 修改 倒计时时间this.time = 5const timeId = setInterval(() => {this.time--// 到了 0 关闭定时器if (this.time == 0) {clearInterval(timeId)}}, 1000)})}.width('100%')Divider()Button('登录').width('100%').type(ButtonType.Normal).backgroundColor('#ea6051').margin({ top: 50 })}.padding({ top: 80, left: 40, right: 40 }).width('100%').alignItems(HorizontalAlign.Start)}@BuildertitleBuilder() {Text('短信登录').fontSize(25).fontWeight(600).margin({ bottom: 30 })}
}

效果展示:

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com