setInterval

解释:设定一个定时器,按照指定的周期(以毫秒计)来执行注册的回调函数。

方法参数

Function callback, Number delay

callback 参数说明

回调函数。

delay 参数说明

执行回调函数之间的时间间隔(单位:ms)。

返回值

名称解释

number

定时器的编号。这个值可以传递给 clearInterval 来取消该定时

示例

跳转编辑工具

在开发者工具中打开

在 WEB IDE 中打开

扫码体验

代码示例

百度智能小程序

请使用百度APP扫码

图片示例

setInterval - 图2

代码示例

  • SWAN
  • JS
  1. <view class="wrap">
  2. <view class="card-area">
  3. <view class="top-description border-bottom">
  4. <view>Interval</view>
  5. <view>{{Interval}}</view>
  6. </view>
  7. <button type="primary" bindtap="bindSetInterval">setInterval</button>
  8. <button type="primary" bindtap="bindClearInterval">clearInterval</button>
  9. </view>
  10. <view class="card-area">
  11. <view class="top-description border-bottom">
  12. <view>timeout</view>
  13. <view>{{timeout}}</view>
  14. </view>
  15. <button type="primary" bindtap="bindSetTimeout">setTimeout</button>
  16. <button type="primary" bindtap="bindClearTimeout">clearTimeout</button>
  17. </view>
  18. </view>