h5中console的一些实用的API

本文介绍了HTML5中console的一些实用API,包括console.count用于输出运行次数,console.table用于展示表格形式的数据,console.group和console.groupEnd用于组织输出内容,console.trace用于追踪方法调用来源,console.profile和console.profileEnd用于性能测试,以及console.assert用于条件提示错误。这些API在调试和优化代码时非常有用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

h5中console的一些实用的API

 

console.count(label)  输出运行次数

console.table(object|array)  输出表格形态的数据(在动态绘制的检查时用的较多)

console.group(label) 和 console.groupEnd(label) 将 console 结果进行分组(分类及减少输出版面,但也加大了我们的脑回路呀)(group = groupCollapsed 是一样的)

console.trace() 检测方法的调用来源,超级赞

console.profile(label) 和 console.profileEnd(label) 是 time 的升级版,不但测速,直接测性能了,需要到 profile 面板里面才能看到结果

console.assert(boolean, string) 提示报错可以少个判断

其实 console.error(), console.info(), console.warn() 实在用得少,用好了应该还是很赞的...吧

### HTML5 Video Element Attributes and API Documentation Tutorial The `<video>` element in HTML5 provides a way to embed video content directly into web pages without requiring external plugins. This section covers key attributes of the `<video>` element along with essential APIs for controlling playback. #### Key Attributes of the `<video>` element - **`controls`**: Adds play, pause, volume controls automatically. - **`autoplay`**: Specifies whether the video should begin playing as soon as possible. - **`loop`**: Indicates if the video will restart immediately after reaching the end. - **`muted`**: Sets or returns whether the audio output of the video is muted. - **`preload`**: Advises the browser on how much buffering it should perform[^1]. ```html <video width="320" height="240" controls> <source src="movie.mp4" type="video/mp4"> Your browser does not support the video tag. </video> ``` #### Essential Methods and Properties - **Methods** - `play()`: Starts or resumes playback. - `pause()`: Pauses the current playback. - **Properties** - `currentTime`: Gets or sets the current playback position in seconds. - `duration`: Returns the length of the media resource in seconds. - `volume`: Controls the volume level between 0 and 1. - `paused`: A boolean indicating whether playback has been paused. ```javascript const videoPlayer = document.querySelector('video'); // Play video programmatically videoPlayer.play(); // Pause video programmatically videoPlayer.pause(); ``` #### Event Handling Events allow developers to respond dynamically based on user interaction or changes within the video's state: - **`loadedmetadata`**: Fires once metadata such as duration becomes available. - **`timeupdate`**: Triggered periodically during playback providing updated time information. - **`ended`**: Occurs when playback reaches the end of the stream. ```javascript videoPlayer.addEventListener('ended', () => { console.log('Video has ended'); }); ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

慕容屠苏

你的鼓励是我最大的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值