-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
doc: add oncanplaythrough/onchange document.
- Loading branch information
1 parent
88d721e
commit 6db9598
Showing
3 changed files
with
166 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,80 @@ | ||
oncanplaythrough.md | ||
HTML oncanplaythrough 属性 | ||
=== | ||
|
||
欢迎您编辑 <a target="__blank" href="https://github.com/jaywcjlove/html-tutorial/blob/main/docs/attribute/oncanplaythrough.md">docs/attribute/oncanplaythrough.md</a> 文件,共建 HTML Tutorial 文档。 | ||
## 定义和用法 | ||
|
||
`oncanplaythrough` 事件发生在浏览器估计它可以播放指定的 audio/video 而无需停止缓冲时。 | ||
|
||
## 适用于 | ||
|
||
`oncanplaythrough` 属性是 [事件属性](../reference/eventattributes.md) 的一部分,可用于以下元素: | ||
|
||
| 元素 | 事件 | | ||
| --- | --- | | ||
| [\<audio>](../tags/audio.md) | [canplaythrough](../reference/av/event/canplaythrough.md) | | ||
| [\<video>](../tags/video.md) | [canplaythrough](../reference/av/event/canplaythrough.md) | | ||
<!--rehype:style=width: 100%; display: inline-table;--> | ||
|
||
## 示例 | ||
|
||
### Audio 示例 | ||
|
||
当音频准备好开始播放时运行 `myFunction`: | ||
|
||
```html | ||
<audio oncanplaythrough="myFunction()"> | ||
``` | ||
|
||
|
||
```html idoc:preview:iframe | ||
<script> | ||
function myFunction() { | ||
alert("可以开始播放音频"); | ||
} | ||
</script> | ||
<audio controls oncanplaythrough="myFunction()"> | ||
<source type="audio/ogg" src="horse.ogg"> | ||
<source src="../assets/horse.ogg" type="audio/ogg"> | ||
<source src="../assets/horse.mp3" type="audio/mpeg"> | ||
您的浏览器不支持音频标签。 | ||
</audio> | ||
``` | ||
|
||
|
||
### Video 示例 | ||
|
||
当视频准备好开始播放时运行 `myFunction`: | ||
|
||
```html | ||
<video oncanplaythrough="myFunction()"> | ||
``` | ||
|
||
```html idoc:preview:iframe | ||
<script> | ||
function myFunction() { | ||
alert("可以开始播放视频了"); | ||
} | ||
</script> | ||
<video width="320" controls oncanplaythrough="myFunction()"> | ||
<source type="video/mp4" src="../assets/mov_bbb.mp4"> | ||
<source type="video/ogm" src="../assets/mov_bbb.ogm"> | ||
您的浏览器不支持 video 标签。 | ||
</video> | ||
``` | ||
|
||
## 浏览器支持 | ||
|
||
`oncanplaythrough` 属性对每个元素都有以下浏览器支持: | ||
|
||
| 元素 | ![chrome][1] | ![edge][2] | ![firefox][3] | ![safari][4] | ![opera][5] | | ||
| --- | --- | --- | --- | --- | --- | | ||
| audio | Yes | 9.0 | Yes | Yes | Yes | | ||
| video | Yes | 9.0 | Yes | Yes | Yes | | ||
<!--rehype:style=width: 100%; display: inline-table;--> | ||
|
||
|
||
[1]: ../assets/chrome.svg | ||
[2]: ../assets/edge.svg | ||
[3]: ../assets/firefox.svg | ||
[4]: ../assets/safari.svg | ||
[5]: ../assets/opera.svg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,84 @@ | ||
onchange.md | ||
HTML onchange 属性 | ||
=== | ||
|
||
欢迎您编辑 <a target="__blank" href="https://github.com/jaywcjlove/html-tutorial/blob/main/docs/attribute/onchange.md">docs/attribute/onchange.md</a> 文件,共建 HTML Tutorial 文档。 | ||
## 定义和用法 | ||
|
||
`onchange` 属性会在元素的值发生更改时触发。 | ||
|
||
**提示:** 此事件类似于 `oninput` 事件。 不同之处在于,`oninput` 事件会在元素的值发生更改后立即发生,而 `onchange` 会在元素失去焦点时发生。 另一个区别是 `onchange` 事件也适用于 `<select>` 元素。 | ||
|
||
## 适用于 | ||
|
||
`onchange` 属性是 [事件属性](../reference/attributes.md) 的一部分,可用于任何 HTML 元素。 | ||
|
||
| 元素 | 事件 | | ||
| --- | --- | | ||
| 所有 HTML 元素 | [onchange](../events/onchange.md) | | ||
<!--rehype:style=width: 100%; display: inline-table;--> | ||
|
||
## 示例 | ||
|
||
### Select 示例 | ||
|
||
当用户更改 \<select> 元素的选定选项时执行 JavaScript: | ||
|
||
|
||
```html | ||
<select onchange="myFunction()"> | ||
``` | ||
|
||
```html idoc:preview:iframe | ||
<select id="mySelect" onchange="myFunction()"> | ||
<option value="Audi">Audi | ||
<option value="BMW">BMW | ||
<option value="Mercedes">Mercedes | ||
<option value="Volvo">Volvo | ||
</select> | ||
<p> | ||
当您选择一辆新车时,会触发一个函数,该函数会输出所选汽车的值。 | ||
</p> | ||
<p id="demo"></p> | ||
<script> | ||
function myFunction() { | ||
var x = document.getElementById("mySelect").value; | ||
document.getElementById("demo").innerHTML = "You selected: " + x; | ||
} | ||
</script> | ||
``` | ||
|
||
### Input 示例 | ||
|
||
当用户更改输入字段的内容时执行 JavaScript: | ||
|
||
```html | ||
<input type="text" name="txt" value="Hello" onchange="myFunction(this.value)"> | ||
``` | ||
|
||
```html idoc:preview:iframe | ||
<p> | ||
修改输入字段中的文本,然后在字段外单击以触发 onchange 事件。 | ||
</p> | ||
输入一些文字:<input type="text" name="txt" value="Hello" onchange="myFunction(this.value)"> | ||
<p id="demo"></p> | ||
<script> | ||
function myFunction(val) { | ||
console.log('~~~') | ||
document.getElementById("demo").innerHTML = "输入值已更改。 新值是:" + val; | ||
} | ||
</script> | ||
``` | ||
|
||
## 浏览器支持 | ||
|
||
| 元素 | ![chrome][1] | ![edge][2] | ![firefox][3] | ![safari][4] | ![opera][5] | | ||
| --- | --- | --- | --- | --- | --- | | ||
| onchange | Yes | Yes | Yes | Yes | Yes | | ||
<!--rehype:style=width: 100%; display: inline-table;--> | ||
|
||
|
||
[1]: ../assets/chrome.svg | ||
[2]: ../assets/edge.svg | ||
[3]: ../assets/firefox.svg | ||
[4]: ../assets/safari.svg | ||
[5]: ../assets/opera.svg | ||
|